470,849 Members | 1,175 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Question about validating schema with xml file

Please give me your advice!

I made two files according to xml book, but when validating these two
files,
it gives me an error that I totally don't understand.

Is there a problem in these codes?

I checked xml and schema files through these following sites:
http://tools.decisionsoft.com/schemaValidate/
http://www.xmlme.com/Validator.aspx

XML file:
<?xml version="1.0" encoding="utf-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="kool" xsi:schemaLocation="test.xsd">
<number>89</number>
</document>

Schema file:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns="kool" targetNamespace="kool" xmlns:xsd="http://
www.w3.org/2001/XMLSchema">

<xsd:element name="document" type="documentType"/>

<xsd:complexType name="documentType">
<xsd:sequence>
<xsd:element name="number" type="CustomNumber"/>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="CustomNumber">
<xsd:restriction base="xsd:integer">
<xsd:maxInclusive value="1000"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Jul 2 '08 #1
3 3479
jh3an wrote:
Please give me your advice!

I made two files according to xml book, but when validating these two
files,
it gives me an error that I totally don't understand.
Well you will have to tell us the exact error message if you want help
on that.

<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="kool" xsi:schemaLocation="test.xsd">
schemaLocation takes pairs of namespaceURI schemaURI so you need
xsi:schemaLocation="kool test.xsd"
<xsd:schema xmlns="kool" targetNamespace="kool" xmlns:xsd="http://
www.w3.org/2001/XMLSchema">
Add
elementFormDefault="qualified"
to the xsd:schema element.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 2 '08 #2
Error message differs:
from http://www.xmlme.com/Validator.aspx :
Schema Error: System.Xml.Schema.XmlSchemaException: Expected schema
root. Make sure the root element is and the namespace is 'http://
www.w3.org/2001/XMLSchema' for an XSD schema or 'urn:schemas-microsoft-
com:xml-data' for an XDR schema. at
System.Xml.Schema.XmlSchemaCollection.SendValidati onEvent(XmlSchemaException
e) at System.Xml.Schema.XmlSchemaCollection.Add(String ns, XmlReader
reader, XmlResolver resolver) at
System.Xml.Schema.XmlSchemaCollection.Add(String ns, XmlReader reader)
at Validator.Button1_Click(Object sender, EventArgs e)
from http://tools.decisionsoft.com/schemaValidate/ :
Well Formed: VALID
Schema Validation: INVALID

The following errors were found:
TYPE LOC MESSAGE
Warning 3, 44 SchemaLocation: schemaLocation value = 'test.xsd' must
have even number of URI's.
Validation 4, 9 cvc-complex-type.2.4.a: Invalid content was found
starting with element 'number'. One of '{"":number}' is expected.
Jul 2 '08 #3
jh3an wrote:
Error message differs:
from http://www.xmlme.com/Validator.aspx :
Schema Error: System.Xml.Schema.XmlSchemaException: Expected schema
root. Make sure the root element is and the namespace is 'http://
www.w3.org/2001/XMLSchema' for an XSD schema or 'urn:schemas-microsoft-
com:xml-data' for an XDR schema. at
System.Xml.Schema.XmlSchemaCollection.SendValidati onEvent(XmlSchemaException
e) at System.Xml.Schema.XmlSchemaCollection.Add(String ns, XmlReader
reader, XmlResolver resolver) at
System.Xml.Schema.XmlSchemaCollection.Add(String ns, XmlReader reader)
at Validator.Button1_Click(Object sender, EventArgs e)
That sounds as if you have presented the wrong file as the schema.

from http://tools.decisionsoft.com/schemaValidate/ :
Well Formed: VALID
Schema Validation: INVALID

The following errors were found:
TYPE LOC MESSAGE
Warning 3, 44 SchemaLocation: schemaLocation value = 'test.xsd' must
have even number of URI's.
That is what I told you, the schemaLocation is a list of pairs of the
namespace URI and the schema URL.
Validation 4, 9 cvc-complex-type.2.4.a: Invalid content was found
starting with element 'number'. One of '{"":number}' is expected.
Yes, your schema needs elementFormDefault="qualified", as I already told
you.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 2 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by maddalimurali | last post: by
3 posts views Thread by Uwe Kuhne | last post: by
1 post views Thread by Christian | last post: by
reply views Thread by First_step_to_xml | last post: by
5 posts views Thread by William Johnston | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.