Include statement, it drives me nuts!

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

    #1

    Include statement, it drives me nuts!

    Hi!

    I'm trying with a really simple test, to use a schema within another, but
    xmlspy keeps giving me error message: Schema Error - undefined value for
    'type' encountered!

    The file PersonGroup.xsd refuses to validate the Person type, even though
    the include element. I know it finds the Person.xsd file, because I get a
    "not found" error if I change the schemaLocation value. I thought I was
    doing everything by the book, I just cant find the mistake!

    It is as simple as this:

    File: Person.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace ="http://www.test.com/schemas"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.test.com/schemas" elementFormDefa ult="qualified"
    attributeFormDe fault="unqualif ied">
    <xs:element name="Person">
    <xs:complexType >
    <xs:sequence>
    <xs:element name="Phonenumb er" type="xs:string "/>
    <xs:element name="Firstname " type="xs:string "/>
    <xs:element name="Lastname" type="xs:string "/>
    </xs:sequence>
    <xs:attribute name="Id" type="xs:ID" use="required"/>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    File: PersonGroup.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace ="http://www.test.com/schemas"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.test.com/schemas" elementFormDefa ult="qualified" >
    <xs:include schemaLocation= "Person.xsd "/>
    <xs:element name="PersonGro up">
    <xs:complexType >
    <xs:sequence maxOccurs="unbo unded">
    <xs:element name="Name"/>
    <xs:choice minOccurs="0" maxOccurs="unbo unded">
    <xs:element name="aPerson" type="Person" />
    <xs:element name="PersonId" type="xs:IDREF"/>
    </xs:choice>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    regards

    Karl Z


  • Priscilla Walmsley

    #2
    Re: Include statement, it drives me nuts!

    Hi,

    The "type" attribute has to refer to a type (complex or simple). Your
    "Person" defined in the included schema is an element, not a type. You
    should either change it to:

    element ref="Person"

    or make Person a complex type rather than an element.

    Hope that helps,
    Priscilla

    -----------------------------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema (Prentice Hall PTR)
    -----------------------------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    • Karl

      #3
      Re: Include statement, it drives me nuts!

      Hi again!

      Yes, it helped, now I can reference the schemas from each other!

      Unfortunately, I got another very strange problem, when I try to use the
      simple schema, person.xsd.

      Xmlspy gives me "No content model available for validation (possible empty
      DTD/Schema)", in the Person.xsd when I try to save my test.xml file, which
      is very simple indeed:

      Test.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <Person xmlns="http://www.test.com/schemas"
      xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocat ion="http://www.test.com/schemas
      C:\vcs\Source\I mport_export_fo rmats\Schemas\P erson.xsd">
      </Person>

      Person.xsd
      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema targetNamespace ="http://www.test.com/schemas"
      xmlns="http://www.test.com/schemas"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefa ult="qualified"
      attributeFormDe fault="unqualif ied">
      <xs:complexTy pe name="Person">
      <xs:sequence>
      <xs:element name="Phonenumb er" type="xs:string "/>
      <xs:element name="Firstname " type="xs:string "/>
      <xs:element name="Lastname" type="xs:string "/>
      </xs:sequence>
      <xs:attribute name="Id" type="xs:ID" use="required"/>
      </xs:complexType>
      </xs:schema>

      Is there something obvious I've missed?

      regards

      Karl Z

      "Priscilla Walmsley" <nospam@datypic .com> wrote in message
      news:40b5173c$0 $209$75868355@n ews.frii.net...[color=blue]
      > Hi,
      >
      > The "type" attribute has to refer to a type (complex or simple). Your
      > "Person" defined in the included schema is an element, not a type. You
      > should either change it to:
      >
      > element ref="Person"
      >
      > or make Person a complex type rather than an element.
      >
      > Hope that helps,
      > Priscilla
      >
      > -----------------------------------------------------
      > Priscilla Walmsley
      > Author, Definitive XML Schema (Prentice Hall PTR)
      > -----------------------------------------------------
      >
      > *** Sent via Developersdex http://www.developersdex.com ***
      > Don't just participate in USENET...get rewarded for it![/color]


      Comment

      • Priscilla Walmsley

        #4
        Re: Include statement, it drives me nuts!

        Hi,

        Yes, you do also need to have an element named Person. In the first
        example you gave me, the Person element was declared in your other
        schema. In this case, the Person element is not declared anywhere.

        If you add:

        <xs:element name="Person" type="Person"/>

        it should work.

        Priscilla

        -----------------------------------------------------
        Priscilla Walmsley
        Author, Definitive XML Schema (Prentice Hall PTR)
        -----------------------------------------------------

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Karl

          #5
          Re: Include statement, it drives me nuts!

          It did the trick! Thanks a lot!

          "Priscilla Walmsley" <nospam@datypic .com> wrote in message
          news:40b5ce06$0 $204$75868355@n ews.frii.net...[color=blue]
          > Hi,
          >
          > Yes, you do also need to have an element named Person. In the first
          > example you gave me, the Person element was declared in your other
          > schema. In this case, the Person element is not declared anywhere.
          >
          > If you add:
          >
          > <xs:element name="Person" type="Person"/>
          >
          > it should work.
          >
          > Priscilla
          >
          > -----------------------------------------------------
          > Priscilla Walmsley
          > Author, Definitive XML Schema (Prentice Hall PTR)
          > -----------------------------------------------------
          >
          > *** Sent via Developersdex http://www.developersdex.com ***
          > Don't just participate in USENET...get rewarded for it![/color]


          Comment

          Working...