| xml Schema + ant+xerces-j2 = >validate = > error? | xml Schema + ant+xerces-j2 = >validate = > error? 2004-02-09 - By M. Emal Alekozai
xml Schema + ant+xerces-j2 =>validate => error?
Hi, I want to validate an xml document against a xml schema. I'm using apache ant 1 .6.0. (Ant itself uses apache xerces) I always get the following error: ------- Buildfile: build.xml
validate: [xmlvalidate] /home/www/web596/files/test/xmlSchema/xml/build.xml:1:58: cvc-elt .1: Cannot find the declaration of element 'project'.
BUILD FAILED /home/www/web596/files/test/xmlSchema/xml/build.xml:4: /home/www/web596/files/test/xmlSchema/xml/build.xml is not a valid XML document.
Total time: 3 seconds ------- The xml and the schema file are from the xerces example files (the schould be correct) Does anone know were the error lies (it is my first expirences with schema)? Sorry for posting such a long text.
thanks and regards emal
-------------------- personal-schema.xml-------------------------
<?xml version="1.0" encoding="UTF-8"?> <personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='personal.xsd'>
<person id="Big.Boss" > <name><family>Boss</family> <given>Big</given></name> <email>chief@(protected)</email> <link subordinates="one.worker two.worker three.worker four.worker five .worker"/> </person>
<person id="one.worker"> <name><family>Worker</family> <given>One</given></name> <email>one@(protected)</email> <link manager="Big.Boss"/> </person>
<person id="two.worker"> <name><family>Worker</family> <given>Two</given></name> <email>two@(protected)</email> <link manager="Big.Boss"/> </person>
<person id="three.worker"> <name><family>Worker</family> <given>Three</given></name> <email>three@(protected)</email> <link manager="Big.Boss"/> </person>
<person id="four.worker"> <name><family>Worker</family> <given>Four</given></name> <email>four@(protected)</email> <link manager="Big.Boss"/> </person>
<person id="five.worker"> <name><family>Worker</family> <given>Five</given></name> <email>five@(protected)</email> <link manager="Big.Boss"/> </person>
</personnel>
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name="personnel"> <xs:complexType> <xs:sequence> <xs:element ref="person" minOccurs='1' maxOccurs='unbounded'/> </xs:sequence> </xs:complexType>
<xs:unique name="unique1"> <xs:selector xpath="person"/> <xs:field xpath="name/given"/> <xs:field xpath="name/family"/> </xs:unique> <xs:key name='empid'> <xs:selector xpath="person"/> <xs:field xpath="@(protected)"/> </xs:key> <xs:keyref name="keyref1" refer='empid'> <xs:selector xpath="person"/> <xs:field xpath="link/@(protected)"/> </xs:keyref>
</xs:element>
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element ref="name"/> <xs:element ref="email" minOccurs='0' maxOccurs='unbounded'/> <xs:element ref="url" minOccurs='0' maxOccurs='unbounded'/> <xs:element ref="link" minOccurs='0' maxOccurs='1'/> </xs:sequence> <xs:attribute name="id" type="xs:ID" use='required'/> <xs:attribute name="note" type="xs:string"/> <xs:attribute name="contr" default="false"> <xs:simpleType> <xs:restriction base = "xs:string"> <xs:enumeration value="true"/> <xs:enumeration value="false"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="salary" type="xs:integer"/> </xs:complexType> </xs:element>
<xs:element name="name"> <xs:complexType> <xs:all> <xs:element ref="family"/> <xs:element ref="given"/> </xs:all> </xs:complexType> </xs:element>
<xs:element name="family" type='xs:string'/>
<xs:element name="given" type='xs:string'/>
<xs:element name="email" type='xs:string'/>
<xs:element name="url"> <xs:complexType> <xs:attribute name="href" type="xs:string" default="http://"/> </xs:complexType> </xs:element>
<xs:element name="link"> <xs:complexType> <xs:attribute name="manager" type="xs:IDREF"/> <xs:attribute name="subordinates" type="xs:IDREFS"/> </xs:complexType> </xs:element>
<xs:notation name='gif' public='-//APP/Photoshop/4.0' system='photoshop.exe'/>
</xs:schema> ----------------------------------------------------------------
--------------------- build.xml (for Ant)----------------------- <project name="MyProject" default="validate" basedir="."> <description>Test XMl Schema</description> <target name="validate" depends="" description="validate against xml schema" > <xmlvalidate failonerror="yes" lenient="no" warn="yes"> <fileset dir="." includes="**/*.xml"/> <attribute name="http://xml.org/sax/features/validation" value="true "/> <attribute name="http://apache.org/xml/features/validation/schema" value="true"/> </xmlvalidate> </target> </project> ----------------------------------------------------------------
------------Output of Ant in verbose mode------------------
emal@(protected):~/web596/files/test/xmlSchema/xml$ ant -verbose Apache Ant version 1.6.0 compiled on December 18 2003 Buildfile: build.xml Detected Java version: 1.4 in: /usr/local/DIR/j2sdk1.4.0_01/jre Detected OS: Linux parsing buildfile /home/www/web596/files/test/xmlSchema/xml/build.xml with URI = file:///home/www/web596/files/test/xmlSchema/xml/build.xml Project base dir set to: /home/www/web596/files/test/xmlSchema/xml Build sequence for target `validate' is [validate] Complete build sequence is [validate, ]
validate: [xmlvalidate] Using SAX2 reader org.apache.xerces.parsers.SAXParser [xmlvalidate] Validating build.xml... [xmlvalidate] /home/www/web596/files/test/xmlSchema/xml/build.xml:1:58: cvc-elt .1: Cannot find the declaration of element 'project'.
BUILD FAILED /home/www/web596/files/test/xmlSchema/xml/build.xml:4: /home/www/web596/files/test/xmlSchema/xml/build.xml is not a valid XML document. at org.apache.tools.ant.taskdefs.optional.XMLValidateTask.doValidate (XMLValidateTask.java:426) at org.apache.tools.ant.taskdefs.optional.XMLValidateTask.execute (XMLValidateTask.java:301) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306) at org.apache.tools.ant.Task.perform(Task.java:401) at org.apache.tools.ant.Target.execute(Target.java:338) at org.apache.tools.ant.Target.performTasks(Target.java:365) at org.apache.tools.ant.Project.executeTarget(Project.java:1237) at org.apache.tools.ant.Project.executeTargets(Project.java:1094) at org.apache.tools.ant.Main.runBuild(Main.java:669) at org.apache.tools.ant.Main.startAnt(Main.java:220) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90)
Total time: 3 seconds emal@(protected):~/web596/files/test/xmlSchema/xml$ ----------------------------------------------------------------
--------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@(protected) For additional commands, e-mail: user-help@(protected)
|
|
 |