By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

XML Schema with unnkown Element names

P: n/a
Hi,

I need to validate a XML document where some of the element names are
unnknown.

<xs:any processContents="lax"/> or "skip" allows me to do so.

But: I want to validate those elements - the only thing unknown is the
name of the elements. Especially the attributes are well-known and
need to be validated.

a) Is there any option to use regExp with the name attribute?

b) Or any other way to describe elements with unnkonw names?

I cannot change the XML instance document.

Thanks! Mark

Example data:

<?xml version="1.0"?>
<root>
<WellKnown Type="TypeFromList" Name="anyName">
<UnknownA Type="TypeFromList" Width="200">
<UnknownChildA Type="String"/>
<UnknownChildB Type="String"/>
</UnknownA>
<UnknownB Type="TypeFromList" Width="200">
<UnknownChildC Type="Date"/>
<UnknownChildD Type="Currency"/>
</UnknownB>
</WellKnown>
<WellKnown Type="TypeFromList" Name="anyOtherName"/>
</root>

- how do I validate those Type-attributes of the Unnkown* elements?
Mar 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You can do it by using xsi:type in the instance as shown below:
<WellKnown xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UnknownA xsi:type="unKnownTypeWithAtt" Type="123">
<UnknownChildA Type="String" xsi:type="unKnownTypeWithAtt"/>
<UnknownChildB Type="345" xsi:type="unKnownTypeWithAtt"/>
</UnknownA>
</WellKnown>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="WellKnown" type="unKnownTypeWithAtt">
</xs:element>

<xs:complexType name="unKnownTypeWithAtt">
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Type" type="xs:int"/>
</xs:complexType>
</xs:schema>

There is no other way in XML Schema to describe elements with unknown names
except xs:any.

Thanks,
Priya

"Mark Doerbandt" <sp**********@doerbandt.de> wrote in message
news:dv**********@dit8.doerbandt.de...
Hi,

I need to validate a XML document where some of the element names are
unnknown.

<xs:any processContents="lax"/> or "skip" allows me to do so.

But: I want to validate those elements - the only thing unknown is the
name of the elements. Especially the attributes are well-known and
need to be validated.

a) Is there any option to use regExp with the name attribute?

b) Or any other way to describe elements with unnkonw names?

I cannot change the XML instance document.

Thanks! Mark

Example data:

<?xml version="1.0"?>
<root>
<WellKnown Type="TypeFromList" Name="anyName">
<UnknownA Type="TypeFromList" Width="200">
<UnknownChildA Type="String"/>
<UnknownChildB Type="String"/>
</UnknownA>
<UnknownB Type="TypeFromList" Width="200">
<UnknownChildC Type="Date"/>
<UnknownChildD Type="Currency"/>
</UnknownB>
</WellKnown>
<WellKnown Type="TypeFromList" Name="anyOtherName"/>
</root>

- how do I validate those Type-attributes of the Unnkown* elements?

Mar 20 '06 #2

P: n/a
Thanks, Priya,

Priya Lakshminarayanan:
You can do it by using xsi:type in the instance
for your response.
I cannot change the XML instance document.


Unfortonately I'd have to change the instance for that - and I'm not
able to do so.
There is no other way in XML Schema to describe elements
with unknown names except xs:any.


OK - so I'll have to talk to my customer so /they'll/ change the
schema.

Mark
Mar 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.