XML Schema Wont Work in Codeplot

Discussion in 'XML' started by Chase Preuninger, May 11, 2008.

  1. Here is my schema...

    <?xml version="1.0"?>
    <schema>
    <element name="name">
    <complexType>
    <sequence>
    <element name="first" type="string"/>
    <element name="middle" type="string"/>
    <element name="last" type="string"/>
    </sequence>
    </complexType>
    </element>
    </schema>


    Here is my XML document...
    <?xml version="1.0"?>
    <name xsi:schemaLocation="TestSchema.xml">
    <first>Chase</first>
    <middle>T</middle>
    <last>Preuninger</last>
    </name>

    Here is the parser output...

    [Error] Document is invalid: no grammar found. Line 2, Column 6
    [Error] Document root element "name", must match DOCTYPE root "null".
    Line 2, Column 6
    Chase Preuninger, May 11, 2008
    #1
    1. Advertising

  2. Chase Preuninger wrote:
    > Here is my schema...
    >
    > <?xml version="1.0"?>
    > <schema>


    If you want to use the W3C XML schema language then you need to declare
    a namespace e.g.
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    and make sure the other elements are in that namespace too, as the type
    like xs:string have to be.

    > <element name="name">
    > <complexType>
    > <sequence>
    > <element name="first" type="string"/>
    > <element name="middle" type="string"/>
    > <element name="last" type="string"/>
    > </sequence>
    > </complexType>
    > </element>
    > </schema>
    >
    >
    > Here is my XML document...
    > <?xml version="1.0"?>
    > <name xsi:schemaLocation="TestSchema.xml">


    Your schema does not have a targetNamespace therefore you do not need
    xsi:schemaLocation but rather xsi:noNamespaceSchemaLocation e.g.
    <name
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="TestSchema.xml">




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 11, 2008
    #2
    1. Advertising

  3. Is there any way I could avoid using name spaces all tougher?
    Chase Preuninger, May 11, 2008
    #3
  4. * Chase Preuninger wrote in comp.text.xml:
    >Is there any way I could avoid using name spaces all tougher?


    No, if you don't put the XML Schema attributes and elements into the
    right namespace, applications cannot recognize them as XML Schema.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
    Bjoern Hoehrmann, May 11, 2008
    #4
  5. Chase Preuninger

    Peter Flynn Guest

    Chase Preuninger wrote:
    > Is there any way I could avoid using name spaces all tougher?


    Use a DTD instead.

    <?xml version="1.0"?>
    <!DOCTYPE name [
    <!ELEMENT name (first,middle?,last)>
    <!ELEMENT first (#PCDATA)>
    <!ELEMENT middle (#PCDATA)>
    <!ELEMENT last (#PCDATA)>
    ]>
    <name>
    <first>Chase</first>
    <middle>T</middle>
    <last>Preuninger</last>
    </name>

    But if you want complex validation, you need to use a Schema.

    ///Peter
    Peter Flynn, May 11, 2008
    #5
  6. Chase Preuninger wrote:
    > Is there any way I could avoid using name spaces all tougher?


    You can use the W3C XML schema language to define elements and
    attributes in no namespace, simply by not having a targetNamespace as
    you did. But for the schema elements itself you need to apply the
    namespace http://www.w3.org/2001/XMLSchema, otherwise your "schema" is
    not recognized as one. And if you want to use the schema instance
    attributes like schemaLocation or noNamespaceSchemaLocation, then you
    need to declare the namespace http://www.w3.org/2001/XMLSchema-instance
    as well, otherwise they are not recognized as well.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 11, 2008
    #6
    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. Markus
    Replies:
    1
    Views:
    1,497
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    925
    Martin Honnen
    Feb 5, 2004
  3. Hari Om
    Replies:
    1
    Views:
    451
    Martin SChukrazy
    Mar 2, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,172
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    3
    Views:
    2,797
Loading...

Share This Page