Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Question about validating schema with xml file

Question posted by: jh3an (Guest) on July 2nd, 2008 11:45 AM
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>
Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
July 2nd, 2008
12:25 PM
#2

Re: Question about validating schema with xml file
jh3an wrote:
Quote:
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.

Quote:
<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"
Quote:
<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/

jh3an's Avatar
jh3an
Guest
n/a Posts
July 2nd, 2008
05:15 PM
#3

Re: Question about validating schema with xml file
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.

Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
July 2nd, 2008
05:35 PM
#4

Re: Question about validating schema with xml file
jh3an wrote:
Quote:
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.

Quote:
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.
Quote:
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/

 
Not the answer you were looking for? Post your question . . .
189,798 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors