View Full Version : XML issue
alex57
11-08-2006, 12:08 PM
I have an xml document:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cswk.xsl"?>
<article name="Baker 2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="cswk.xsd">
<title>Emerging grid standards</title>
<author>C. and Brown, J., Baker, M. and Apon, A. and Ferner</author>
<year>2005</year>
<month>April</month>
<journal>Computer</journal>
<volume>38</volume>
<pages>43-50</pages>
<doi>10.1109/MC.2005.124</doi>
<owner>mab</owner>
<timestamp>2006-10-22</timestamp>
</article>
<article name="Baker 2005">
<title>Emerging grid standards</title>
<author>C. and Brown, J., Baker, M. and Apon, A. and Ferner</author>
<year>2005</year>
<month>April</month>
<journal>Computer</journal>
<volume>38</volume>
<pages>43-50</pages>
<doi>10.1109/MC.2005.124</doi>
<owner>mab</owner>
<timestamp>2006-10-22</timestamp>
</article>
and a schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="article">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="year" type="xs:integer"/>
<xs:element name="month" type="xs:string"/>
<xs:element name="journal" type="xs:string"/>
<xs:element name="volume" type="xs:integer"/>
<xs:element name="pages" type="xs:string"/>
<xs:element name="doi" type="xs:string"/>
<xs:element name="owner" type="xs:string"/>
<xs:element name="timestamp" type="xs:date"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
However when I try to validate the xml against the schema I get an error at the second <article> tag in the xml document. What is the matter?
Thanks
rpgfan3233
11-08-2006, 06:30 PM
XML requires a root element to enclose the document. For example, in HTML, you use the HTML element to enclose the HEAD and the BODY elements. Without the HTML element, HEAD and BODY would be invalid because they don't have a root element.
alex57
11-08-2006, 07:00 PM
I changed my xml document and schema to this. Is this what you mean? Still doesnt validate
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cswk.xsl"?>
<references>
<article name="Baker 2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="cswk.xsd">
<title>Emerging grid standards</title>
<author>C. and Brown, J., Baker, M. and Apon, A. and Ferner</author>
<year>2005</year>
<month>April</month>
<journal>Computer</journal>
<volume>38</volume>
<pages>43-50</pages>
<doi>10.1109/MC.2005.124</doi>
<owner>mab</owner>
<timestamp>2006-10-22</timestamp>
</article>
<article name="Baker 2005">
<title>Emerging grid standards</title>
<author>C. and Brown, J., Baker, M. and Apon, A. and Ferner</author>
<year>2005</year>
<month>April</month>
<journal>Computer</journal>
<volume>38</volume>
<pages>43-50</pages>
<doi>10.1109/MC.2005.124</doi>
<owner>mab</owner>
<timestamp>2006-10-22</timestamp>
</article>
</references>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="references">
<xs:element name="article">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="year" type="xs:integer"/>
<xs:element name="month" type="xs:string"/>
<xs:element name="journal" type="xs:string"/>
<xs:element name="volume" type="xs:integer"/>
<xs:element name="pages" type="xs:string"/>
<xs:element name="doi" type="xs:string"/>
<xs:element name="owner" type="xs:string"/>
<xs:element name="timestamp" type="xs:date"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>
rpgfan3233
11-09-2006, 08:35 PM
Don't you need
<xs:element name="references">
<xs:complexType>
<xs:element name="article">
...
</xs:element>
</xs:complexType>
</xs:element>?
alex57
11-09-2006, 11:12 PM
I changed the xml and schema to:
nb/ changed declaration from article element to reference element
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="cswk.xsl"?>
<references xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="cswk.xsd">
<article name="Baker 2005">
<title>Emerging grid standards</title>
<author>C. and Brown, J., Baker, M. and Apon, A. and Ferner</author>
<year>2005</year>
<month>April</month>
<journal>Computer</journal>
<volume>38</volume>
<pages>43-50</pages>
<doi>10.1109/MC.2005.124</doi>
<owner>mab</owner>
<timestamp>2006-10-22</timestamp>
</article>
<article name="Baker 2005">
<title>Emerging grid standards</title>
<author>C. and Brown, J., Baker, M. and Apon, A. and Ferner</author>
<year>2005</year>
<month>April</month>
<journal>Computer</journal>
<volume>38</volume>
<pages>43-50</pages>
<doi>10.1109/MC.2005.124</doi>
<owner>mab</owner>
<timestamp>2006-10-22</timestamp>
</article>
</references>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="references">
<xs:complexType>
<xs:element name="article">
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="year" type="xs:integer"/>
<xs:element name="month" type="xs:string"/>
<xs:element name="journal" type="xs:string"/>
<xs:element name="volume" type="xs:integer"/>
<xs:element name="pages" type="xs:string"/>
<xs:element name="doi" type="xs:string"/>
<xs:element name="owner" type="xs:string"/>
<xs:element name="timestamp" type="xs:date"/>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:schema>
The error in xmlspy when validating reads:
"Unable to load a schema with target namespace " from 'cswk.xsd'
error location references"
rpgfan3233
11-10-2006, 01:19 AM
I'm not sure about that error since I don't use XMLSpy, but that error sounds like something is wrong with XMLSpy or it is just misleading. I just realized that I forgot about the <xs:sequence> element. :p I think you can also use <xs:all> to allow for the elements to appear in any order.
<xs:element name="references">
<xs:complexType>
<xs:sequence>
<xs:element name="article">
...
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
alex57
11-10-2006, 03:42 PM
My schema is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="references">
<xs:complexType>
<xs:sequence>
<xs:element name="article">
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="year" type="xs:integer"/>
<xs:element name="month" type="xs:string"/>
<xs:element name="journal" type="xs:string"/>
<xs:element name="volume" type="xs:integer"/>
<xs:element name="pages" type="xs:string"/>
<xs:element name="doi" type="xs:string"/>
<xs:element name="owner" type="xs:string"/>
<xs:element name="timestamp" type="xs:date"/>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
The error i receive from Oxygen XML is
"E s4s-elt-must match.1: The content of 'article' must match (annotation ?, (simpletype | conplextype)?, (unique | key | keyref)*)). A problem was found starting at: element.
Any further ideas?? Thanks
david_kw
11-11-2006, 12:56 AM
I know nothing about schema but might not article require xs:complexType and xs:sequence also? It was in your first version but got taken out somewhere along the way (maybe for a good reason).
Just a thought.
david_kw
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.