Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Validation with XML schema in Oscript

Status
Not open for further replies.

nicolas46

Programmer
Mar 4, 2010
33
FR
Hello everybody,

I'm trying to validate my XML file with and XML schema but I get validations errors where there is not. It is like it doesn't understand my xsd

My XML :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<personne>
    <nom>MBODJ</nom>
    <prenom>Babacar</prenom>
    <date_naissance>1996-10-06</date_naissance>
    <etablissement>NIIT</etablissement>
 </personne>

My XSD :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
<xs:element name="personne">
  <xs:complexType>
	<xs:sequence>
	  <xs:element name="nom" type="xs:string" />
	  <xs:element name="prenom" type="xs:string" />
	  <xs:element name="date_naissance" type="xs:date" />
	  <xs:element name="etablissement" type="xs:string" />
	  <xs:element name="num_tel" type="xs:string" />
	</xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>
My Oscript script :
Code:
function void main()

	//Tableau de retour des résultats de la validation
	Assoc lRetParseur = Undefined
	//Fichiers utilisés
	String lXmlFile = "C:\OPENTEXT\testXMLTools\fichier1.xml"
	String lXsdFile = "C:\OPENTEXT\testXMLTools\fichier1.xsd"
	
	//Validation
	lRetParseur = validation(lXmlFile, lXsdFile)	
	Echo (lRetParseur)
	
end


function Assoc validation (String pXmlFile, String pXsdFile)

	Assoc lRoRet
	
	Echo ("Fonction de validation : Vérification de l'existance des fichiers")
	
	if (File.Exists(pXmlFile)  && File.Exists(pXsdFile))
		
		Echo ("OK")
		//Création du parseur
		lRoRet = Assoc.CreateAssoc()
		
		DOMParser lparseur = DOMParser.New()
			
		//Localisation du xsd
		lparseur.setExternalSchemaLocation(pXsdFile)
		
		
		//Pour que le parseur rapporte toutes les erreurs
		lparseur.setValidationScheme(DomParser.Val_Always)
		lparseur.setDoSchema(TRUE)
		lparseur.SetValidationSchemaFullChecking(TRUE)
	
		//Parsage
		lRoRet = lparseur.parse(pXmlFile)
		
	else
		Echo ("KO")
		lRoRet = Undefined
	end
	
	return lRoRet

end


My Output :
Code:
A<1,?,'Errors'=V{<'ErrType','ErrMsg','PublicID','SystemID','LineNumber','ColumnNumber'><2,'Unknown element \'personne\'','C:\\OPENTEXT\\testXMLTools\\fichier1.xml','',2,10><2,'Unknown element \'nom\'','C:\\OPENTEXT\\testXMLTools\\fichier1.xml','',3,9><2,'Unknown element \'prenom\'','C:\\OPENTEXT\\testXMLTools\\fichier1.xml','',4,12><2,'Unknown element \'date_naissance\'','C:\\OPENTEXT\\testXMLTools\\fichier1.xml','',5,20><2,'Unknown element \'etablissement\'','C:\\OPENTEXT\\testXMLTools\\fichier1.xml','',6,19>},'OK'=false>

Thanks for helping me.
 
I cannot understand french but is your xml based on a validating DTD then the order will definitely matter.

I have ahad problems writing classification XML if I do not follow the the validating dtd.

Try avoiding oscript and check with aregular xml syntax checker.If you think that your files don't have a problem,iform OT and ask why it is going wrong.

BTW I do very little programming with XML data structures

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008
 
Thanks for yours advices.

In fact, I found the solution. I forgot to write this line in my script [sadeyes] :

lparseur.SetDoNamespaces(TRUE)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top