Question about validating schema with xml file

Discussion in 'XML' started by jh3an, Jul 2, 2008.

  1. jh3an

    jh3an Guest

    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>
    jh3an, Jul 2, 2008
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Jul 2, 2008
    #2
    1. Advertising

  3. jh3an

    jh3an Guest

    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.SendValidationEvent(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.
    jh3an, Jul 2, 2008
    #3
  4. 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.SendValidationEvent(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/
    Martin Honnen, Jul 2, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Jessel
    Replies:
    0
    Views:
    399
    Ben Jessel
    Aug 5, 2004
  2. Markus
    Replies:
    1
    Views:
    1,518
    Markus
    Nov 23, 2005
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,244
    Stanimir Stamenkov
    Apr 25, 2005
  4. First_step_to_xml
    Replies:
    0
    Views:
    702
    First_step_to_xml
    Jun 28, 2006
  5. Replies:
    3
    Views:
    2,829
Loading...

Share This Page