define static content in XML-Schema / Relax NG

Discussion in 'XML' started by mhuhn.de@gmail.com, Jul 22, 2005.

  1. Guest

    I am using XML Schema for quite a while but haven't written a single
    line of Relax NG yet.

    For what I know, I cannot define static content within an XML Schema.
    For example, I have the following structure:

    <colors>
    <color>green</color>
    <color>red</color>
    </colors>

    With XML-Schema, I can say colors should have to elements of type
    color, and color can contain "green" or "red". But I cannot say that
    the content has to be exactly as posted above. Is this correct?

    Is there a way to do this in Relax NG?

    I need it for more levels than just one. I want to be able to define a
    whole XML-Document within the "Schema", so only a document with exactly
    that content will be valid.
     
    , Jul 22, 2005
    #1
    1. Advertising

  2. If you don't care about the order in which colors appear, you can do this in
    xml schema. Depending on how complex your schema is, you might be able to
    to something like this for more than just one level.

    <?xml version="1.0" encoding="utf-8" ?>

    <xs:schema targetNamespace="foo"

    elementFormDefault="qualified"

    xmlns="foo"

    xmlns:foo="foo"

    xmlns:xs="http://www.w3.org/2001/XMLSchema">



    <xs:simpleType name="colorType">

    <xs:restriction base="xs:string">

    <xs:enumeration value="green"/>

    <xs:enumeration value="red"/>

    </xs:restriction>

    </xs:simpleType>

    <xs:element name="colors">

    <xs:complexType>

    <xs:sequence>

    <xs:element name="color" type="colorType" minOccurs="2"
    maxOccurs="2"/>

    </xs:sequence>

    </xs:complexType>

    <xs:unique name="uniqueColors">

    <xs:selector xpath="foo:color"/>

    <xs:field xpath="."/>

    </xs:unique>

    </xs:element>

    </xs:schema>


    --
    Stan Kitsis
    Program Manager, XML Technologies
    Microsoft Corporation

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm


    <> wrote in message
    news:...
    >I am using XML Schema for quite a while but haven't written a single
    > line of Relax NG yet.
    >
    > For what I know, I cannot define static content within an XML Schema.
    > For example, I have the following structure:
    >
    > <colors>
    > <color>green</color>
    > <color>red</color>
    > </colors>
    >
    > With XML-Schema, I can say colors should have to elements of type
    > color, and color can contain "green" or "red". But I cannot say that
    > the content has to be exactly as posted above. Is this correct?
    >
    > Is there a way to do this in Relax NG?
    >
    > I need it for more levels than just one. I want to be able to define a
    > whole XML-Document within the "Schema", so only a document with exactly
    > that content will be valid.
    >
     
    Stan Kitsis [MSFT], Jul 26, 2005
    #2
    1. Advertising

  3. Guest

    Thanks for your answer but the order does play an important role in
    this project. I already found out that with Relax NG it is possible to
    define the order and therefore static content. Even though it is also
    quite "talkative" so you cannot just write how it has to look.
     
    , Jul 30, 2005
    #3
  4. I don't get it. If the exact content is predetermined, what information does
    the document convey?

    If a large section of a document must be boilerplate for content from a
    specific source, why not make a schema and documents such that the boilerplate
    content is excluded, then use XSLT to insert the boilerplate content after the
    initial validation is done?

    Finally, if inserting the content fixed later is not an option, you could use
    a combination of XML Schema and Schematron since Schematron makes it easy to
    validate data content. In the case below, you just first assert that, in the
    context of "/colors", "color[1]='green' and color[2]='red'"

    On 22 Jul 2005 09:24:41 -0700, wrote:

    >I am using XML Schema for quite a while but haven't written a single
    >line of Relax NG yet.
    >
    >For what I know, I cannot define static content within an XML Schema.
    >For example, I have the following structure:
    >
    ><colors>
    > <color>green</color>
    > <color>red</color>
    ></colors>
    >
    >With XML-Schema, I can say colors should have to elements of type
    >color, and color can contain "green" or "red". But I cannot say that
    >the content has to be exactly as posted above. Is this correct?
    >
    >Is there a way to do this in Relax NG?
    >
    >I need it for more levels than just one. I want to be able to define a
    >whole XML-Document within the "Schema", so only a document with exactly
    >that content will be valid.
     
    Steve Jorgensen, Jul 31, 2005
    #4
  5. I don't get it. If the exact content is predetermined, what information does
    the document convey?

    If a large section of a document must be boilerplate for content from a
    specific source, why not make a schema and documents such that the boilerplate
    content is excluded, then use XSLT to insert the boilerplate content after the
    initial validation is done?

    Finally, if inserting the content fixed later is not an option, you could use
    a combination of XML Schema and Schematron since Schematron makes it easy to
    validate data content. In the case below, you just first assert that, in the
    context of "/colors", "color[1]='green' and color[2]='red'"

    On 22 Jul 2005 09:24:41 -0700, wrote:

    >I am using XML Schema for quite a while but haven't written a single
    >line of Relax NG yet.
    >
    >For what I know, I cannot define static content within an XML Schema.
    >For example, I have the following structure:
    >
    ><colors>
    > <color>green</color>
    > <color>red</color>
    ></colors>
    >
    >With XML-Schema, I can say colors should have to elements of type
    >color, and color can contain "green" or "red". But I cannot say that
    >the content has to be exactly as posted above. Is this correct?
    >
    >Is there a way to do this in Relax NG?
    >
    >I need it for more levels than just one. I want to be able to define a
    >whole XML-Document within the "Schema", so only a document with exactly
    >that content will be valid.
     
    Steve Jorgensen, Jul 31, 2005
    #5
  6. Guest

    It is (normally) not the whole document that is predetermined but I
    want the possibility to predetermine large parts of a document.
    Furthermore, I want to use the same mechanism (i.e. W3C XML Schema) to
    validate. In addition to validation I want to use this schema (or
    better call it template) to generate a valid XML file without further
    information.
    I use a modified version of W3C Schema now, i have an element called
    "template" where I can predetermine fixed parts and also include
    dynamic elements again. Looks like that:
    ....
    <xs:complexType name="colorsType">
    <xc:template>
    <color>red</color>
    <color>blue</color>
    <color xs:type="colorType" xs:minOccurs="0" xs:maxOccurs="4" />
    </xc:template>
    </xs:complexType>
    ....

    This is ok for my purpose and it works as an "XML constructor" as I
    provide initial values for regular pattern values for example. But I
    have to write my own validator which is quite a lot of work. You
    schematron suggestion is nice for validation but doesn't work for
    creation. I need it all in one file.
     
    , Aug 2, 2005
    #6
  7. On 2 Aug 2005 03:30:50 -0700, wrote:

    >It is (normally) not the whole document that is predetermined but I
    >want the possibility to predetermine large parts of a document.
    >Furthermore, I want to use the same mechanism (i.e. W3C XML Schema) to
    >validate. In addition to validation I want to use this schema (or
    >better call it template) to generate a valid XML file without further
    >information.
    >I use a modified version of W3C Schema now, i have an element called
    >"template" where I can predetermine fixed parts and also include
    >dynamic elements again. Looks like that:
    >...
    ><xs:complexType name="colorsType">
    > <xc:template>
    > <color>red</color>
    > <color>blue</color>
    > <color xs:type="colorType" xs:minOccurs="0" xs:maxOccurs="4" />
    > </xc:template>
    ></xs:complexType>
    >...
    >
    >This is ok for my purpose and it works as an "XML constructor" as I
    >provide initial values for regular pattern values for example. But I
    >have to write my own validator which is quite a lot of work. You
    >schematron suggestion is nice for validation but doesn't work for
    >creation. I need it all in one file.


    No XML tools I know of were really built to do what you're describing in
    regard to performing both generation and validation. If you can make it work
    at all, it's going to be a terrible kludge.
     
    Steve Jorgensen, Aug 2, 2005
    #7
    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,541
    Markus
    Nov 23, 2005
  2. Pieter
    Replies:
    6
    Views:
    427
    Pieter
    Nov 28, 2003
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,264
    Stanimir Stamenkov
    Apr 25, 2005
  4. The xmlBlueprint Team
    Replies:
    0
    Views:
    387
    The xmlBlueprint Team
    Sep 1, 2006
  5. Robert Dailey
    Replies:
    1
    Views:
    735
    Bjoern Hoehrmann
    Jul 19, 2007
Loading...

Share This Page