Mixing schemas

A

Arndt Jonasson

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
 
G

George Bina

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.
Schema, Relax NG or Schematron as schema languages.

Best Regards,
George
 
A

Arndt Jonasson

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?
 
G

George Bina

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
 
G

George Bina

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

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

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?
 
A

Arndt Jonasson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top