Page 1 of 1

cvc.elt1: Cannot find the declartion of element "xs:sch

Posted: Wed Aug 17, 2005 12:48 pm
by Coup
Hi everybody,

Just started messing around with XML and its schemas with Oxygen, but am having trouble getting any of it to work, due to this peculiar error -

cvc.elt1: Cannot find the declartion of element "xs:schema"

This was happening for a while with my first mock ups, so i went and copied the first tutorial of xml.com and i still get teh same thing. Complains about the the secodn line from the xml's point of view and then when i try and to a 'Vailidate with..' (all the other tests show it to be fine) and enter http://www.w3.org/2001/XMLSchema i get the above error back.

Obviously i've got sumting wrong somewhere but can't for the life of me find out where it is!! Please can some one help me!!

Heres the xsd -

Code: Select all


<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="character" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="friend-of" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="since" type="xs:date"/>
<xs:element name="qualification" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
and the xml i'm using

Code: Select all


<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="character" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="friend-of" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="since" type="xs:date"/>
<xs:element name="qualification" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks for any ideas clues pointers, anything at all that you think would be helpful.

Coup

Posted: Wed Aug 17, 2005 1:23 pm
by george
Hi Coup,

What you label as XML is also a schema file, you should open that with the XSD editor. An instance document for the schema file you posted and labeled as a xsd should start like below:

<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="book.xsd">
<title>test</title>
<author></author>
...

You may take a look at the sample project that comes with oXygen, see personal-schema.xml for a sample instance document of the personal.xsd schema.

Best Regards,
George

Posted: Wed Aug 17, 2005 1:52 pm
by Coup
Hi George,

First thank you for your very quick reply, very helpful it was to! Second sorry about that miss posting of the xml file, was surposed to be my example but was having some trouble getting stuff into the form (firefox kept bring up the find bar and putting all my typing/pasting in there, most annoying!).

Have tried the samples and get what looks likes good results, except (you knew it was coming :)) i get a complaint about the doctype
Document root element "personnel", must match DOCTYPE root "null".
and another about the grammer
Document is invalid: no grammar found.
I also get this
Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'personnel'.
Are these ligit problems or are they just moans? Is does seem to be working apart from these.

Thanks again

Coup

Posted: Wed Aug 17, 2005 2:14 pm
by george
Hi Coup,

Both [oxygen/samples/personal.xml and [oxygen]/samples/personal-schema.xml are valid and should be reported valid by oXygen if you use the default options and the "Validate" action.
If you have problems please post the exact documents to reproduce the problem and a schor description of the steps we should take to reproduce that.

Best Regards,
George

Posted: Wed Aug 17, 2005 2:37 pm
by Coup
Hi george,

Bascially i am trying to parse the documents againist the schema in java, with the view to having xml files being posted to a servlet, validated via the schema then passed deeper into the system for processing, etc. (I realize this now mayb abit off topic for this forum but i'll struggle on anyway.) Using the following code

Code: Select all


DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
SchemaFactory sFact = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = sFact.newSchema(schemaFile);
factory.setSchema(schema);
DocumentBuilder dommer = factory.newDocumentBuilder();
DOMImplementation domImpl = dommer.getDOMImplementation();
System.out.println("Domimpl = "+domImpl.toString());
Document doco = dommer.parse(xmlFile);
Where schemaFile is set to /eclipsepluginsfolder/oxygenplugin[/]/personnal.xsd and xmlFile is set to /eclipsepluginsfolder/oxygenplugin[/]/personnal-schema.xml.

The output is

Domimpl = com.sun.org.apache.xerces.internal.dom.DOMImplementationImpl@11f2ee1
Warning: validation was turned on but an org.xml.sax.ErrorHandler was not set, which is probably not what is desired. Parser will use a default ErrorHandler to print the first 10 errors. Please call the setErrorHandler method to fix this.
Error: URI = "file:///opt/eclipse/plugins/com.oxygenxml.editor_6.1.0/samples/personal-schema.xml", Line = "3", : Document root element "personnel", must match DOCTYPE root "null".
Error: URI = "file:///opt/eclipse/plugins/com.oxygenxml.editor_6.1.0/samples/personal-schema.xml", Line = "3", : Document is invalid: no grammar found.
Error: URI = "file:///opt/eclipse/plugins/com.oxygenxml.editor_6.1.0/samples/personal-schema.xml", Line = "3", : cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'personnel'.
Error: URI = "file:///opt/eclipse/plugins/com.oxygenxml.editor_6.1.0/samples/personal-schema.xml", Line = "3", : cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'personnel'.

After this i can output the elements in doco with no problems. This is using Eclispe 3.0 and a new jdk1.5 as the jvm. Not quite sure what you meant by a 'schor', but hopefully this gives you enuff info about what i'm trying to achieve.

Thank you for your help thus far.

Coup

Posted: Thu Aug 18, 2005 12:23 pm
by george
Have a look at the Xerces samples and maybe you should try also using Xerces 2.7.0 instead of the Xerces bundled with Java 1.5.

Best Regards,
George

Posted: Thu Aug 18, 2005 1:35 pm
by Coup
Hi Geogre,

Have tried inserting the newer version but i still get the same old errors. Have found a work around by defining the DTD in the XML (thou in production this will have to be seperate). Is this in any way normal, having to have a dtd below yr schema? i thought it was a replacemnt not an addition. Prehaps you cld clear that up for me.

Cheers

Coup

Posted: Thu Aug 18, 2005 2:02 pm
by george
You may try setting the schemaLanguage property to specify that you want validation only against XML Schema:

setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema"
)

Best Regards,
George

Posted: Thu Aug 18, 2005 4:00 pm
by Coup
hey geogre,

Tried that, setting it on the initial DocBuilderFactory, and i still get the same errors......

Cheers

Posted: Thu Aug 18, 2005 4:47 pm
by george
You may find this recent thread on the Xerces-user list interesting, it discusses exactly this issue. I recomment again working with Xerces 2.7.1, I do not know what Xerces version Java 1.5 picked up...

http://marc.theaimsgroup.com/?l=xerces- ... 021493&w=2
http://marc.theaimsgroup.com/?t=112311878700001&r=1&w=2

Best Regards,
George

Posted: Fri Aug 19, 2005 12:21 pm
by Coup
Hi George,

Thanks for those links cleared a lot of stuff up. Just struggling with the actual schema now!

Cheers

coup