XML Schema Wont Work in Codeplot

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chase Preuninger

    XML Schema Wont Work in Codeplot

    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:schemaLocat ion="TestSchema .xml">
    <first>Chase</first>
    <middle>T</middle>
    <last>Preuninge r</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
  • Martin Honnen

    #2
    Re: XML Schema Wont Work in Codeplot

    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:schemaLocat ion="TestSchema .xml">
    Your schema does not have a targetNamespace therefore you do not need
    xsi:schemaLocat ion but rather xsi:noNamespace SchemaLocation e.g.
    <name
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespace SchemaLocation= "TestSchema.xml ">




    --

    Martin Honnen

    Comment

    • Chase Preuninger

      #3
      Re: XML Schema Wont Work in Codeplot

      Is there any way I could avoid using name spaces all tougher?

      Comment

      • Bjoern Hoehrmann

        #4
        Re: XML Schema Wont Work in Codeplot

        * 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:bjoern@h oehrmann.de · 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/

        Comment

        • Peter Flynn

          #5
          Re: XML Schema Wont Work in Codeplot

          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>Preuninge r</last>
          </name>

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

          ///Peter

          Comment

          • Martin Honnen

            #6
            Re: XML Schema Wont Work in Codeplot

            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 noNamespaceSche maLocation, 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

            Comment

            Working...