Validating XML data

Kevin Partin

Usenet Archive
Joined
Feb 11, 2004
Messages
3
Reaction score
0
I have an XML data file that I want to validate using an XML Schema. The XML data file is saved to a file named 'eigen.xml' and is shown below:

<?xml version="1.0" ?>

<eigenvalues xsi:noNamespaceSchemaLocation="eigen.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <fred> <eigenvalue>3.850019E-07</eigenvalue> <radians>6.204852E-04</radians> <cycles>9.875329E-05</cycles> </fred> <mode> <eigenvalue>1.506695E-06</eigenvalue> <radians>1.227475E-03</radians> <cycles>1.953587E-04</cycles> </mode> <mode> <eigenvalue>2.165626E-06</eigenvalue> <radians>1.471607E-03</radians> <cycles>2.342135E-04</cycles> </mode> <mode> <eigenvalue>3.912464E-06</eigenvalue> <radians>1.977995E-03</radians> <cycles>3.148077E-04</cycles> </mode> </eigenvalues>

The XML schema file saved to the file 'eigen.xsd' and is located in the same directory as the XML data file.

<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="eigenvalues">
<xs:element ref="mode" minOccurs="1" maxOccurs="unbounded"/> </xs:element>

<xs:element name="mode">
<xs:complexType>
<xs:all>
<xs:element ref="eigenvalue"/>
<xs:element ref="radians"/>
<xs:element ref="cycles"/>
</xs:all>
</xs:complexType>
</xs:element>

<xs:element name="eigenvalue" type="xs:double"/>
<xs:element name="radians" type="xs:double"/>
<xs:element name="cycles" type="xs:double"/>

</xs:schema>

I have introduced an intentional error in the data file (there is no element named 'fred' in the schema) in an attempt to study how errors are handled. However, I am not sure that I have referenced the schema file correctly in the data file. I am trying to view the file in Mozilla 1.6 and MS Explorer 6.0 and each browser does not flag the error. I would appreciate it if someone can help me understand what I am doing wrong. I am new to XML and have been reading the O'Reilly books 'Learning XML' and 'XML Schema', but I must still be missing something.

Thank you,

Kevin
 

peterpeter

Usenet Archive
Joined
Feb 11, 2004
Messages
4
Reaction score
0
Hi.

You refer the schema correctly. The problem is, that usually no browser validates a xml document against a given schema. You need a XML tool like XML Spy or Stylus Studio (there are many more and some are for free, you should search the web). They offer many useful functions to develop XML and of course a schema validation.

Bye
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top