Validating XML data

K

Kevin Partin

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
 
P

peterpeter

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

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top