XSD type derived via restriction in same namespace as restricted type?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • burkley@gmail.com

    XSD type derived via restriction in same namespace as restricted type?

    In XML Schema, is it possible to derive a complex type via restriction
    and have the new derived type be in a different namespace than the
    original base type?

    I've banged on this for 2 days now and I'm starting to think the
    answer is no. I've searched this group and have not seen anything
    discussing this.
    >From Walmsley: "The values for the new type are a subset of those for
    the base type. All values of the restricted type are also valid
    according to the base type".

    Now since all values of the restricted type are also valid according
    to the base type, it follows that the namespace of the derived type
    must be the same as the namespace of the base type. Otherwise the
    instances of the derived type would not conform to the base type.

    My question: Is it possible to derive a complex type via restriction
    and have the new derived type be in a different namespace than the
    original base type?

  • George Bina

    #2
    Re: XSD type derived via restriction in same namespace as restricted type?

    Yes, it is possible.
    The thing that you should take into account is that XML Schema
    requires a different file to define a different namespace, so you
    cannot derive the type and have it in a different namespace in the
    same file as the base type.

    Here you have an example:

    base.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace ="http://www.oxygenxml.c om/ns/base">
    <xs:simpleTyp e name="test">
    <xs:restricti on base="xs:string ">
    <xs:maxLength value="10"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:schema>

    restricted.xsd

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace ="http://www.oxygenxml.c om/ns/restricted"
    xmlns:base="htt p://www.oxygenxml.c om/ns/base">
    <xs:import namespace="http ://www.oxygenxml.c om/ns/base"
    schemaLocation= "base.xsd"/>

    <xs:simpleTyp e name="restricte dTest">
    <xs:restricti on base="base:test ">
    <xs:enumerati on value="val1"/>
    <xs:enumerati on value="val2"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:schema>

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina - http://aboutxml.blogspot.com/
    <oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger




    Comment

    • Priscilla Walmsley

      #3
      Re: XSD type derived via restriction in same namespace as restricted type?

      Hi,

      If you're talking about complex types, the type name itself can be in a
      different namespace. But the child element names must be in the same
      namespace (or no namespace in both types.)

      So, if you are using elementFormDefa ult="qualified" , or you are using
      the "ref" attribute to refer to globally declared elements, it won't
      work to have the derived type in another namespace.

      If you are using elementFormDefa ult="unqualifie d" and all your element
      declarations are local, it can work.

      Hope that helps,
      Priscilla

      -----------------------------------------------
      Priscilla Walmsley
      Author, Definitive XML Schema (2001, Pren Hall)
      XQuery (2007, O'Reilly Media)

      Hundreds of reusable examples of XQuery functions from the FunctX XQuery Function Library

      -----------------------------------------------

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • usenet@tech-know-ware.com

        #4
        Re: XSD type derived via restriction in same namespace as restricted type?

        On 17 Sep, 15:38, Priscilla Walmsley <nos...@datypic .comwrote:
        Hi,
        >
        If you're talking about complex types, the type name itself can be in a
        different namespace. But the child element names must be in the same
        namespace (or no namespace in both types.)
        >
        So, if you are using elementFormDefa ult="qualified" , or you are using
        the "ref" attribute to refer to globally declared elements, it won't
        work to have the derived type in another namespace.
        Hi Priscilla,

        Taking the case where the elements used the ref='' variant, would it
        be OK in the above case to have the elements of the restricted type
        echo the elements of the base type, and then restrict the attributes
        associated with the complex type (assuming
        attributeFormDe fault='false')?
        If you are using elementFormDefa ult="unqualifie d" and all your element
        declarations are local, it can work.
        Cheers,

        Pete.
        =============== =============== ===============
        Pete Cordell
        Codalogic
        for XML Schema to C++ data binding visit
        Codalogic LMX generates customized C++ code to read and write your XML data. Simplifies and speeds up code development and helps reduce bugs.

        =============== =============== ===============

        Comment

        • Priscilla Walmsley

          #5
          Re: XSD type derived via restriction in same namespace as restricted type?

          Hi Pete,

          Oh yes, sure - I didn't think of that case. If you are "ref"-ing the
          element declarations that are in the original namespace, it's OK (they
          can be the same child elements or a restricted set of those child
          elements).

          Its just if you were "ref"-ing element in the new namespace that would
          cause a problem.

          And yes, it works in a parallel way for attributes. If you use
          attributeFormDe fault="unqualif ied" (the default behavior), you're fine.
          If you're using attributes in namespaces, the attributes have to be in
          the same namespace in the restricted type.

          Thanks,
          Priscilla

          ---------------------------------------------
          Priscilla Walmsley
          Author, XQuery (2007, O'Reilly Media)

          Hundreds of reusable examples of XQuery functions from the FunctX XQuery Function Library

          ---------------------------------------------

          *** Sent via Developersdex http://www.developersdex.com ***

          Comment

          • usenet@tech-know-ware.com

            #6
            Re: XSD type derived via restriction in same namespace as restricted type?

            On 17 Sep, 17:21, Priscilla Walmsley <nos...@datypic .comwrote:
            Hi Pete,
            >
            Oh yes, sure - I didn't think of that case. If you are "ref"-ing the ...
            Thanks Priscilla. I'll admit it was a pretty contrived case, and
            probably not that useful, but I wanted to check my understanding.

            Cheers,

            Pete.
            =============== =============== ===============
            Pete Cordell
            Codalogic
            for XML Schema to C++ data binding visit
            Codalogic LMX generates customized C++ code to read and write your XML data. Simplifies and speeds up code development and helps reduce bugs.

            =============== =============== ===============

            Comment

            • burkley@gmail.com

              #7
              Re: XSD type derived via restriction in same namespace as restricted type?

              I made a few mistakes in my example XSDs/instances. I'm re-posting
              FYI. I welcome any comments.

              ----------------------------------------------
              XDSs for option 1
              ----------------------------------------------

              -- Base XSD, filename BaseWithLocalEl ementDefs.xsd

              <?xml version="1.0" encoding="UTF-8"?>
              <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns="http://www.example.org/Base"
              targetNamespace ="http://www.example.org/Base"
              elementFormDefa ult="unqualifie d">

              <xs:element name="A" type="AType" />
              <xs:complexTy pe name="AType">
              <xs:sequence>
              <xs:element name="E1" type="xs:string " />
              <xs:element name="E2" type="xs:string " minOccurs="0" />
              </xs:sequence>
              </xs:complexType>
              </xs:schema>

              -- Restricting XSD, with restricted types in different namespace.
              filename RestrictionWith LocalElementDef s.xsd

              <?xml version="1.0" encoding="UTF-8"?>
              <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns="http://www.example.org/Restriction"
              targetNamespace ="http://www.example.org/Restriction"
              xmlns:base="htt p://www.example.org/Base"
              elementFormDefa ult="unqualifie d">

              <xs:import namespace="http ://www.example.org/Base"
              schemaLocation= "BaseWithLocalE lementDefs.xsd" />

              <xs:element name="ARestrict ed" type="ARestrict edType" />
              <xs:complexTy pe name="ARestrict edType">
              <xs:complexCont ent>
              <xs:restricti on base="base:ATyp e">
              <xs:sequence>
              <xs:element name="E1" type="xs:string " />
              </xs:sequence>
              </xs:restriction>
              </xs:complexConte nt>
              </xs:complexType>
              </xs:schema>

              -- Instance

              <?xml version="1.0" encoding="UTF-8"?>
              <res:ARestricte d xmlns:res="http ://www.example.org/Restriction"
              xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocat ion="http://www.example.org/Restriction
              RestrictionWith LocalElementDef s.xsd ">
              <E1>E1</E1>
              </res:ARestricted >


              ----------------------------------------------
              XDSs for option 2
              ----------------------------------------------

              -- Base XSD, filename BaseWithGlobalE lementDefs.xsd

              <?xml version="1.0" encoding="UTF-8"?>
              <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns="http://www.example.org/Base"
              targetNamespace ="http://www.example.org/Base"
              elementFormDefa ult="qualified" >

              <xs:element name="E1" type="E1Type" />
              <xs:simpleTyp e name="E1Type">
              <xs:restricti on base="xs:string " />
              </xs:simpleType>

              <xs:element name="E2" type="E2Type" />
              <xs:simpleTyp e name="E2Type">
              <xs:restricti on base="xs:string " />
              </xs:simpleType>

              <xs:element name="A" type="AType" />
              <xs:complexTy pe name="AType">
              <xs:sequence>
              <xs:element ref="E1" />
              <xs:element ref="E2" minOccurs="0" />
              </xs:sequence>
              </xs:complexType>
              </xs:schema>

              -- Restricting XSD, filename RestrictionWith GlobalElementDe fs.xsd

              <?xml version="1.0" encoding="UTF-8"?>
              <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns="http://www.example.org/Restriction"
              targetNamespace ="http://www.example.org/Restriction"
              xmlns:base="htt p://www.example.org/Base"
              elementFormDefa ult="qualified" >

              <xs:import namespace="http ://www.example.org/Base"
              schemaLocation= "BaseWithGlobal ElementDefs.xsd " />

              <xs:element name="ARestrict ed" type="ARestrict edType" />
              <xs:complexTy pe name="ARestrict edType">
              <xs:complexCont ent>
              <xs:restricti on base="base:ATyp e">
              <xs:sequence>
              <xs:element ref="base:E1" />
              </xs:sequence>
              </xs:restriction>
              </xs:complexConte nt>
              </xs:complexType>
              </xs:schema>

              -- Instance

              <?xml version="1.0" encoding="UTF-8"?>
              <res:ARestricte d xmlns:res="http ://www.example.org/Restriction"
              xmlns:base="htt p://www.example.org/Base"
              xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocat ion="http://www.example.org/Restriction
              RestrictionWith GlobalElementDe fs.xsd ">
              <base:E1>E1</base:E1>
              </res:ARestricted >


              Comment

              Working...