This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > April 2007 > how to create schema with changable element name





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author how to create schema with changable element name
fj

2007-04-20, 3:18 am

I have XML file similar to this
<ProcessResult>
<person id="11">
<errors>
<field id="persontype">invalid lookup</field>
<field id="lastname">cannot be null</field>
</errors>
</person>
</ProcessResult>

However, the <person> element name is not fixed, it could be <company> for
example, the XML can be
<ProcessResult>
<company id="11">
<errors>
<field id="addresstype">invalid lookup</field>
<field id="name">cannot be null</field>
</errors>
</company>
</ProcessResult>

Is it possible to use one schema for above situations? How can I design this
schema and specify an element without using a fixed name?

Thanks

-fj
usenet@tech-know-ware.com

2007-04-20, 6:17 am

On 20 Apr, 07:12, fj <f...@discussions.microsoft.com> wrote:
> I have XML file similar to this
> <ProcessResult>
> <person id="11">
> <errors>
> <field id="persontype">invalid lookup</field>
> <field id="lastname">cannot be null</field>
> </errors>
> </person>
> </ProcessResult>
>
> However, the <person> element name is not fixed, it could be <company> for
> example, the XML can be
> <ProcessResult>
> <company id="11">
> <errors>
> <field id="addresstype">invalid lookup</field>
> <field id="name">cannot be null</field>
> </errors>
> </company>
> </ProcessResult>
>
> Is it possible to use one schema for above situations? How can I design this
> schema and specify an element without using a fixed name?
>
> Thanks
>
> -fj


Schema's choice construct my help. Perhaps something like:

<xs:element name="ProcessResult">
<xs:complexType>
<xs:choice>
<xs:element name="company" type="MyType"/>
<xs:element name="person" type="MyType"/>
</xs:choice>
</xs:complexType>
</xs:element>

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML Schema to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================


Martin Honnen

2007-04-20, 6:17 pm

fj wrote:

> Is it possible to use one schema for above situations? How can I design this
> schema and specify an element without using a fixed name?


As suggested, if you know the different elements then use choice. If you
want a wild card then use xs:any, see
<http://www.w3.org/TR/xmlschema-0/#any>



--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
fj

2007-04-20, 6:17 pm



"Martin Honnen" wrote:

> fj wrote:
>
>
> As suggested, if you know the different elements then use choice. If you
> want a wild card then use xs:any, see
> <http://www.w3.org/TR/xmlschema-0/#any>
>
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
>


I am trying to give the any element some details, but it is not working,
since the structure of the XML is fixed, the only difference is the element
name in the middle of the XML is changable.

Otherwise, I'll have to write a function to maunally replace the <person>
into a generic element like <Object name="person"> then use my schema to
process it further.

Here is what I tried, which is not working...


<element name="DataErrors">
<complexType>
<sequence>
<any namespace="http://www.w3.org/1999/xhtml" minOccurs="1"
maxOccurs="unbounded" processContents="skip">
<element name="Error" type="string"/>
<element name="Field" type="string"/>
</any>
</sequence>
</complexType>
</element>
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews