Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question XML restrictions

    Hi all,

    I'm trying to describe some structure that works based on restrictions.

    On the first level, I have a general description of my model (this constitutes a first Schema, let's say I describe office furnitures).

    On the second level, I have a more specific description (let's say I define the characteristics of tables, this is a second Schema based on restrictions of the first one).

    The instance will be so a specific table.

    To achieve this model, I use restrictions, which enables me to have something really abstracted on the first level. However, I ran into troubles with the use of restricted subtypes, on how to specifically declare them in the instance and as well in some cases in the restriction itself.

    To make it simpler, I wrote a simple XSD file which you can see bellow and 2 associated questions:

    1. tSubRoot is a kind of tRoot, how in the instance can I specify that I want to use the tSubRoot and not the tRoot for the "root" element? This affects the possible children ...

    2. This document will not validate because of the restriction "tSubRoot": even though I could describe in the instance a "data" child of tData type and a "data" child of tSubData type (since tSubData restricts tData), it seems that I can't specify this restriction:
    -- if I change the name of the node, it's not a good restriction anymore
    -- if I use the same name "data", it complains as well...

    I would very much appreciate some comment/help on this

    Thanks a lot,
    Cyrille

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="ns1"
        targetNamespace="ns1">
        <xs:element name="root" type="tRoot" />
        
        <xs:complexType name="tRoot">
            <xs:sequence>
                <xs:choice maxOccurs="unbounded">
                    <xs:element name="data" type="tData" minOccurs="0" maxOccurs="unbounded"/>
                    <xs:element name="dataOther" type="tDataOther" minOccurs="0" maxOccurs="unbounded" />
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
        
        <xs:complexType name="tSubRoot">
            <xs:complexContent>
                <xs:restriction base="tRoot" >
                    <xs:sequence>
                        <xs:element name="data" type="tData" />
                        <xs:element name="data" type="tSubData" />
                    </xs:sequence>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        
        <xs:complexType name="tData">
            <xs:sequence>
                <xs:choice maxOccurs="unbounded">
                    <xs:element name="el1" type="xs:integer" />
                    <xs:element name="el2" />
                    <xs:element name="el3" />
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
        
        <xs:complexType name="tSubData">
            <xs:complexContent>
                <xs:restriction base="tData" >
                    <xs:sequence>
                        <xs:element name="el1" type="xs:byte" />
                    </xs:sequence>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
        
        <xs:complexType name="tDataOther">
            <xs:sequence>
            </xs:sequence>
        </xs:complexType>
        
        
    </xs:schema>

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    you probably must check this by yourself:

    Code:
        
        <xs:complexType name="tSubRoot">
            <xs:complexContent>
                <xs:restriction base="tRoot" >
                    <xs:sequence>
                        <xs:element name="data" type="tData" />
                        <xs:element name="data" type="tSubData" />
                    </xs:sequence>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
    xs:restriction:can't contain xsl:sequence:

    http://www.w3.org/TR/xmlschema-2/#de...by-restriction

    Code:
        
        <xs:complexType name="tData">
            <xs:sequence>
                <xs:choice maxOccurs="unbounded">
                    <xs:element name="el1" type="xs:integer" />
                    <xs:element name="el2" />
                    <xs:element name="el3" />
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
        
        <xs:complexType name="tSubData">
            <xs:complexContent>
                <xs:restriction base="tData" >
                    <xs:sequence>
                        <xs:element name="el1" type="xs:byte" />
                    </xs:sequence>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
    both are empty elements

    Code:
        
        <xs:complexType name="tDataOther">
            <xs:sequence>
            </xs:sequence>
        </xs:complexType>
    </xs:schema>
    sequence is empty.

    best regards

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    thanks a lot for your answer...

    However, "e12" and "e13", as well as the sequence are empty because it's just a foo-bar example...

    Regarding the restrictions, I can find example for sequencing (and my document is valid from this point of view):
    http://www.w3schools.com/Schema/el_restriction.asp
    http://www.w3.org/TR/xmlschema-1/#declare-type (example bellow?)

    Just a question, when you say:
    you probably must check this by yourself:
    You think there is no solution using only Schemes? I heard from another forum that maybe schematron could be a solution...

    Thanks a lot,
    Best regards

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by licryle View Post
    Hi,

    thanks a lot for your answer...

    However, "e12" and "e13", as well as the sequence are empty because it's just a foo-bar example...

    Regarding the restrictions, I can find example for sequencing (and my document is valid from this point of view):
    http://www.w3schools.com/Schema/el_restriction.asp
    http://www.w3.org/TR/xmlschema-1/#declare-type (example bellow?)

    Just a question, when you say:

    You think there is no solution using only Schemes?
    no, I said that because I use relaxng not xsd,

    one of the goal of a schema is to avoid amiguity or you want to force grammar to be ambigue. Try to find if you really need that because this way you get into a big trouble, .

    I heard from another forum that maybe schematron could be a solution..
    schematron is not a tool?

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •