XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Mark LaneSubject: flexible XSD for extra tags in xml?
Author: Mark Lane
Date: 04 Oct 2005 08:44 AM
Right now my XSD looks like this :(message is defined in xsd too)
<xs:element name="Publish">
<xs:complexType>
<xs:sequence>
<xs:element ref="Message" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

My XML message that I validate against the XSD looks like this :

<?xml version="1.0" encoding="utf-8" ?>
<RtiMsg>
<Header>
<Dest>16</Dest>
<Source></Source>
<UserId>RAMORTON</UserId>
<Version>1.0</Version>
<MsgId>13</MsgId>
<MsgType>Publish</MsgType>
</Header>
<Publish>
<Message>send to only 13</Message>
</Publish>
</RtiMsg>

What I want is to be able to have xml tags created underneath the <Message> tag at runtime. With no limitation of what the new tags are named or how many tags are contained in the Publish Messagetype.
So that the xml message will still be validated by the xsd


<?xml version="1.0" encoding="utf-8" ?>
<RtiMsg>
<Header>
<Dest>16</Dest>
<Source></Source>
<UserId>RAMORTON</UserId>
<Version>1.0</Version>
<MsgId>13</MsgId>
<MsgType>Publish</MsgType>
</Header>
<Publish>
<Message>send to only 13</Message>
<newtag>not explicitly named in the xsd</newtag>
<anytagIwant>tag name will only be known at runtime</anytagIwant>
<asmanytags>as I want</asmanytags>
</Publish>
</RtiMsg>

Postnext
(Deleted User) Subject: flexible XSD for extra tags in xml?
Author: (Deleted User)
Date: 04 Oct 2005 10:47 AM
Take a look at the following schema:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="RtiMessage">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Header"/>
<xsd:element ref="Publish"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Header"/>
<xsd:element name="Publish">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Message"/>
<xsd:any processContents="skip" maxOccurs="unbounded" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>


The key is to use
<xsd:any processContents="skip" maxOccurs="unbounded" minOccurs="0"/>
In your case processContents can be "skip" or "lax". First instructs
XML processor not to validate extra elements at all, second instructs XML processor to obtain schema for the element namespace, but if no schema available XML processor will not generate an error.

Posttop
Mark LaneSubject: flexible XSD for extra tags in xml?
Author: Mark Lane
Date: 04 Oct 2005 11:33 AM
Thank you very much!!! That worked great.
Mark Lane

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.