473,498 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

analysing an XML document and validating with a schema ...

hello,

i'm trying to parse an XML file from a java program, and the structure
of the XML document is described in a schema file.

here is the simple schema file (departement.xsd) :
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="departement">
<xs:complexType>
<xs:sequence>
<xs:element name="ville" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="nom" type="xs:string"/>
<xs:element name="codepostal" type="xs:positiveInteger"/>
<xs:element name="latitude" type="xs:decimal"/>
<xs:element name="longitude" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="num" type="xs:positiveInteger" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

my XML file looks somewhat like that (villes-31.xml):
<?xml version="1.0" encoding="UTF-8"?>
<departement num="31"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="departement.xsd">
<ville>
<nom>Agassac</nom>
<codepostal>31230</codepostal>
<latitude>43.366667</latitude>
<longitude>0.883333</longitude>
</ville>
...
</departement>

and when i parse the xml file with my java program, i get those errors :
Error: URI = "file:villes-31.xml", Line = "2", : Document root element
"departement", must match DOCTYPE root "null".
Error: URI = "file:villes-31.xml", Line = "2", : Document is invalid: no
grammar found.
Error: URI = "file:villes-31.xml", Line = "2", : cvc-complex-type.3.2.2:
Attribute 'xsi:schemaLocation' is not allowed to appear in element
'departement'.
Error: URI = "file:villes-31.xml", Line = "2", : cvc-complex-type.3.2.2:
Attribute 'xsi:schemaLocation' is not allowed to appear in element
'departement'.

but i just did exactly the same as in w3schools.com ... so i don't
understand why he doesn't like my line 2 !

anyone could tell me why ?

thank you in advance !
xs

ps : here is what my java prog looks like :

fabrique = DocumentBuilderFactory.newInstance();
sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCH EMA_NS_URI);
schema = sf.newSchema(fichierSchema);
fabrique.setSchema(schema);
fabrique.setValidating(true);
fabrique.setIgnoringElementContentWhitespace(true) ;
constructeur = fabrique.newDocumentBuilder();
document = constructeur.parse(fichierXML);
Jul 20 '05 #1
0 1169

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3590
by: Will | last post by:
I have been having problems validating an XForms document against the XForms schema located at http://www.w3.org/MarkUp/Forms/2002/XForms-Schema.xsd. I have reduced the XForm to its bare bones...
4
1338
by: Mike | last post by:
I am writing a post-processor for an existing XML document (that I have no control over), this entails a lot of inserting and deleting of nodes. I don't want to have to hard code the...
1
1930
by: TP-Software | last post by:
Hi, What's the fastest way to validate an XML document against an XML Schema? All I need to know is wether or not the document is valid in respect to the Schema Could someone show me an...
1
2942
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
2
2610
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
5
2145
by: Donal McWeeney | last post by:
Hi, Using .Net 2.0 what is the best way to determine the list of schemas used by a XmlDocument. Thanks Donal
1
2862
by: Chris Lieb | last post by:
I have an XML Schema file that I know is correct becuase I currently use it in a VB6 program to validate XML documents. Also, if I load an XML file into VS2005 that is not valid against this...
0
2628
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
1
2797
by: Thomas | last post by:
Does anyone have a best practices recommendation on writing a valid XML document based on a 3rd party XML schema? I have a working solution but I would like to know if anyone has a better...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.