Mixing schemas

Discussion in 'XML' started by Arndt Jonasson, Mar 21, 2007.

  1. I have a schema defining the input of a particular application. Let's
    refer to the namespace for my schema by the prefix "my:". Now the need
    has arisen to annotate such input documents with foreign attributes
    and tags (which my application is to ignore). I see no problems with
    attributes, but there are many ways to do it for elements.

    One way is to use xs:any at the end of every complexType, thereby
    allowing foreign elements at the end.

    Another is to introduce a new element <my:appinfo> similar to
    <xs:appinfo>, letting any foreign elements appear within it, but
    forcing the <my:appinfo> element to be at the beginning of my
    complexTypes, where I already have a <my:description>.

    A third is to extend <my:description> to accept not only text, as
    today, but arbitrary foreign elements.

    A fourth way would be to put <xs:any ... maxOccurs="unbounded">
    between all children in my complexType, allowing foreign elements
    everywhere.

    How is this usually done? Is there a best way? (I want minimum impact
    on my own schema, and maximum usability for the user, and those two
    goals of course are in conflict.)

    /Arndt Jonasson
     
    Arndt Jonasson, Mar 21, 2007
    #1
    1. Advertising

  2. Arndt Jonasson

    George Bina Guest

    Hi,

    The best solution I believe is to use NVDL - namesapce based
    validation and dispatching language. This allows to define fragments
    of the document to be validated with different schemas, thus you do
    not need to make any changes to your schema file.
    For instance in your case you can specify that all the the content in
    your my namespace to be put together and validated with the my.xsd
    schema while content from other namesapces to be allowed. Here it is a
    sample NVDL script for that:

    <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"
    startMode="init">
    <mode name="init">
    <namespace ns="http://my">
    <validate schema="my.xsd" useMode="my"/>
    </namespace>
    </mode>
    <mode name="my">
    <namespace ns="http://my"><attach/></namespace>
    <anyNamespace><allow/></anyNamespace>
    </mode>
    </rules>

    There are a few implementations already for NVDL see www.nvdl.org.
    >From oNVDL (http://www.oxygenxml.com/onvdl.html) you can use XML

    Schema, Relax NG or Schematron as schema languages.

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


    On Mar 21, 3:09 pm, "Arndt Jonasson" <> wrote:
    > I have a schema defining the input of a particular application. Let's
    > refer to the namespace for my schema by the prefix "my:". Now the need
    > has arisen to annotate such input documents with foreign attributes
    > and tags (which my application is to ignore). I see no problems with
    > attributes, but there are many ways to do it for elements.
    >
    > One way is to use xs:any at the end of every complexType, thereby
    > allowing foreign elements at the end.
    >
    > Another is to introduce a new element <my:appinfo> similar to
    > <xs:appinfo>, letting any foreign elements appear within it, but
    > forcing the <my:appinfo> element to be at the beginning of my
    > complexTypes, where I already have a <my:description>.
    >
    > A third is to extend <my:description> to accept not only text, as
    > today, but arbitrary foreign elements.
    >
    > A fourth way would be to put <xs:any ... maxOccurs="unbounded">
    > between all children in my complexType, allowing foreign elements
    > everywhere.
    >
    > How is this usually done? Is there a best way? (I want minimum impact
    > on my own schema, and maximum usability for the user, and those two
    > goals of course are in conflict.)
    >
    > /Arndt Jonasson
     
    George Bina, Mar 22, 2007
    #2
    1. Advertising

  3. On Mar 22, 9:04 am, "George Bina" <> wrote:
    > The best solution I believe is to use NVDL - namesapce based
    > validation and dispatching language. This allows to define fragments
    > of the document to be validated with different schemas, thus you do
    > not need to make any changes to your schema file.
    > For instance in your case you can specify that all the the content in
    > your my namespace to be put together and validated with the my.xsd
    > schema while content from other namesapces to be allowed.


    Thank you. NVDL sounds interesting, but it seems like a more long-term
    option to me.

    Validation is only the first (logical) step in my application. When
    the input has been deemed valid, the elements are processed, and I
    suppose that with NVDL, I would still need to recognize and ignore the
    foreign parts.

    Is NVDL in common use yet? If I go with my original idea of extending
    the application to allow but ignore foreign namespaces in certain
    parts of the document, would a user feel constrained if the foreign
    parts can only occur, say, as the first child elements of each
    element?
     
    Arndt Jonasson, Mar 22, 2007
    #3
  4. Arndt Jonasson

    George Bina Guest

    You can pass the document before getting it to your application
    through an XSLT transformation that filters out the foreign content:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform">
    <xsl:template match="node() | @*">
    <xsl:copy>
    <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="*[namespace-uri()!='http://test']">
    <xsl:apply-templates select="node() | @*"/>
    </xsl:template>
    <xsl:template match="@*[namespace-uri()!='http://test' and namespace-
    uri()!='']"/>
    </xsl:stylesheet>

    Thus your application remains unchanged.

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


    On Mar 22, 11:03 am, "Arndt Jonasson" <>
    wrote:
    > On Mar 22, 9:04 am, "George Bina" <> wrote:
    >
    > > The best solution I believe is to use NVDL - namesapce based
    > > validation and dispatching language. This allows to define fragments
    > > of the document to be validated with different schemas, thus you do
    > > not need to make any changes to your schema file.
    > > For instance in your case you can specify that all the the content in
    > > your my namespace to be put together and validated with the my.xsd
    > > schema while content from other namesapces to be allowed.

    >
    > Thank you. NVDL sounds interesting, but it seems like a more long-term
    > option to me.
    >
    > Validation is only the first (logical) step in my application. When
    > the input has been deemed valid, the elements are processed, and I
    > suppose that with NVDL, I would still need to recognize and ignore the
    > foreign parts.
    >
    > Is NVDL in common use yet? If I go with my original idea of extending
    > the application to allow but ignore foreign namespaces in certain
    > parts of the document, would a user feel constrained if the foreign
    > parts can only occur, say, as the first child elements of each
    > element?
     
    George Bina, Mar 22, 2007
    #4
  5. Arndt Jonasson

    George Bina Guest

    Just an update to the NVDL script, the above example did not accept
    foreign attributes. So a complete and tested example is below,
    assuming the namespace we are interested in is http://test

    <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"
    startMode="init">
    <mode name="init">
    <namespace match="elements" ns="http://test">
    <validate schema="test.xsd" useMode="my"/>
    </namespace>
    </mode>
    <mode name="my">
    <namespace ns="http://test" match="attributes elements"><attach/></
    namespace>
    <namespace ns="" match="attributes"><attach/></namespace>
    <anyNamespace match="attributes elements"><unwrap/></anyNamespace>
    </mode>
    </rules>

    It ignores (unwrap) elements and attributes from foreign namespaces
    and keeps all content that is in the http://test namespace plus
    attributes in no namespace.

    NVDL is new but it is already working. You have 3 implementations to
    choose from and oXygen XML editor provides all the support you need to
    develop and test your NVDL scripts or to edit and validate files
    against NVDL scripts.

    Put NVDL on validation and you solved the validation then run the
    document through a simple XSLT transformation as in my previous
    example and you have both your schema and your application unchanged.

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

    On Mar 22, 11:41 am, "George Bina" <> wrote:
    > You can pass the document before getting it to your application
    > through an XSLT transformation that filters out the foreign content:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    > Transform">
    > <xsl:template match="node() | @*">
    > <xsl:copy>
    > <xsl:apply-templates select="node() | @*"/>
    > </xsl:copy>
    > </xsl:template>
    > <xsl:template match="*[namespace-uri()!='http://test']">
    > <xsl:apply-templates select="node() | @*"/>
    > </xsl:template>
    > <xsl:template match="@*[namespace-uri()!='http://test'and namespace-
    > uri()!='']"/>
    > </xsl:stylesheet>
    >
    > Thus your application remains unchanged.
    >
    > Best Regards,
    > George
    > ---------------------------------------------------------------------
    > George Cristian Bina
    > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debuggerhttp://www.oxygenxml.com
    >
    > On Mar 22, 11:03 am, "Arndt Jonasson" <>
    > wrote:
    >
    > > On Mar 22, 9:04 am, "George Bina" <> wrote:

    >
    > > > The best solution I believe is to use NVDL - namesapce based
    > > > validation and dispatching language. This allows to define fragments
    > > > of the document to be validated with different schemas, thus you do
    > > > not need to make any changes to your schema file.
    > > > For instance in your case you can specify that all the the content in
    > > > your my namespace to be put together and validated with the my.xsd
    > > > schema while content from other namesapces to be allowed.

    >
    > > Thank you. NVDL sounds interesting, but it seems like a more long-term
    > > option to me.

    >
    > > Validation is only the first (logical) step in my application. When
    > > the input has been deemed valid, the elements are processed, and I
    > > suppose that with NVDL, I would still need to recognize and ignore the
    > > foreign parts.

    >
    > > Is NVDL in common use yet? If I go with my original idea of extending
    > > the application to allow but ignore foreign namespaces in certain
    > > parts of the document, would a user feel constrained if the foreign
    > > parts can only occur, say, as the first child elements of each
    > > element?
     
    George Bina, Mar 22, 2007
    #5
  6. On Mar 22, 11:19 am, "George Bina" <> wrote:

    > NVDL is new but it is already working. You have 3 implementations to
    > choose from and oXygen XML editor provides all the support you need to
    > develop and test your NVDL scripts or to edit and validate files
    > against NVDL scripts.
    >
    > Put NVDL on validation and you solved the validation then run the
    > document through a simple XSLT transformation as in my previous
    > example and you have both your schema and your application unchanged.


    Thank you. The problem for me is that my environment is restricted
    from an XML point of view - the language is Erlang, and the system
    contains a schema parser/validator and XPath and not much more. Not
    xslt, for example. So I do have to build knowledge of foreign parts
    into my code (putting xsltproc in the pipeline is an option, of
    course, but somewhat awkward). I suppose my position is somewhat
    unusual, and what people usually do with foreign parts is just filter
    them away first.
     
    Arndt Jonasson, Mar 23, 2007
    #6
    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. Oleg Ogurok

    dynamic color schemas with ASP.NET

    Oleg Ogurok, Jun 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    465
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Jun 8, 2004
  2. Green Start Button

    Microsoft CDO Schemas...

    Green Start Button, Aug 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    673
    Anon-E-Moose
    Aug 11, 2005
  3. Soeren
    Replies:
    2
    Views:
    371
    Waxolunist
    Sep 22, 2004
  4. Alex Molochnikov

    EJB Gurus - switching between DB schemas

    Alex Molochnikov, Mar 6, 2005, in forum: Java
    Replies:
    2
    Views:
    416
    Alex Molochnikov
    Mar 7, 2005
  5. Replies:
    3
    Views:
    809
Loading...

Share This Page