Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Mixing schemas

Reply
Thread Tools

Mixing schemas

 
 
Arndt Jonasson
Guest
Posts: n/a
 
      03-21-2007

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

 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      03-22-2007
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" <(E-Mail Removed)> 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



 
Reply With Quote
 
 
 
 
Arndt Jonasson
Guest
Posts: n/a
 
      03-22-2007
On Mar 22, 9:04 am, "George Bina" <(E-Mail Removed)> 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?

 
Reply With Quote
 
George Bina
Guest
Posts: n/a
 
      03-22-2007
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" xmlnssl="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" <(E-Mail Removed)>
wrote:
> On Mar 22, 9:04 am, "George Bina" <(E-Mail Removed)> 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?



 
Reply With Quote
 
George Bina
Guest
Posts: n/a
 
      03-22-2007
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" <(E-Mail Removed)> 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" xmlnssl="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" <(E-Mail Removed)>
> wrote:
>
> > On Mar 22, 9:04 am, "George Bina" <(E-Mail Removed)> 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?



 
Reply With Quote
 
Arndt Jonasson
Guest
Posts: n/a
 
      03-23-2007
On Mar 22, 11:19 am, "George Bina" <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft CDO Schemas... Green Start Button ASP .Net 1 08-11-2005 09:16 PM
How 2 get single JDOM doc of XML schema that also includes external schemas kyancy@gmail.com Java 3 03-09-2005 07:19 PM
EJB Gurus - switching between DB schemas Alex Molochnikov Java 2 03-07-2005 05:47 PM
Strange problem with JDOM, Xerces and XML Schemas Soeren Java 2 09-22-2004 10:17 AM
dynamic color schemas with ASP.NET Oleg Ogurok ASP .Net 1 06-08-2004 01:06 PM



Advertisments