473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Interesting Problem with Child element order

Hi there, I have an interesting problem that maybe you pros can suggest how I solve.
I'm working with a third party program that serializes an XML document (it was obviously not designed with schema in mind). I created a schema from this document. It works fine. Except for some unknown reason, in a small part of the XML document, this program switches the order around, and of course the validator I built then fails.
Its always the same two elements it switches (from top to bottom and bottom to top)
ex:
Some documents have the metaID on top, some on the bottom, these are the only two elements that ever get switched.
I need my validator program to handle both of the below document types and not throw errors.

Some documents are:

<Metadata>
<MetaID>{65C97878-11D5-4599-B5AD-7C5BFB9B591D}</MetaID>
<CreaDate>20040223</CreaDate>
<CreaTime>08552300</CreaTime>
<SyncOnce>FALSE</SyncOnce>
<SyncDate>20040225</SyncDate>
<SyncTime>10445400</SyncTime>
<ModDate>20040225</ModDate>
<ModTime>10445400</ModTime>
</Metadata>

Some are:
<Metadata>
<CreaDate>20040225</CreaDate>
<CreaTime>09500700</CreaTime>
<SyncOnce>FALSE</SyncOnce>
<SyncDate>20040225</SyncDate>
<SyncTime>10445100</SyncTime>
<ModDate>20040225</ModDate>
<ModTime>10445100</ModTime>
<MetaID>{469F6DEE-4EFF-48E6-9D66-39C0D6776DF2}</MetaID>
</Metadata>
Of course schema by its nature defines the order of child elements. Is there anyway I can force the MetaID element to be ignored? Or should I approach this by adding code to my project to ensure this element is placed first? (as defined in myschema)
I don't know how I should approach this problem.
thanks a bunch!

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 12 '05 #1
1 1748
"Rachel" <jr****@hotmail.com> wrote in message news:eH**************@TK2MSFTNGP12.phx.gbl...
Except for some unknown reason, in a small part of the XML document, this
program switches the order around, and of course the validator I built then fails. : : Some documents have the metaID on top, some on the bottom, these are the
only two elements that ever get switched.


The first idea that might come to mind is to make the MetaID at the top optional
(minOccurs=0, maxOccurs=1) and the MetaID at the bottom optional. This fails
to detect when there is no MetaID (I am assuming MetaID is required, but may
be either the first or last child element), so we dismiss it.

In this scenario, there's really no other way but to declare the sequence twice.
One sequence compositor defines elements in the order: MetaID, CreaDate,
...., ModTime. A second sequence compositor defines elements in the order:
CreaData, ..., ModTime, MetaID. These two compositors are then placed
under a choice compositor, meaning either one sequence or the other is
valid for each instance of the MetaData element.

- - - MetaData1.xsd (excerpt)
<!-- Type definition. -->
<xsd:complexType name="MetaDataType">
<!-- Sequence A _or_ B is valid. -->
<xsd:choice>
<!-- Definition of Sequence A. -->
<xsd:sequence>
<xsd:element name="MetaID" type="xsd:string" />
<xsd:element name="CreaDate" type="xsd:string" />
<!-- . . . -->
<xsd:element name="ModTime" type="xsd:string" />
</xsd:sequence>
<!-- Definition of Sequence B. -->
<xsd:sequence>
<xsd:element name="CreaDate" type="xsd:string" />
<!-- . . . -->
<xsd:element name="ModTime" type="xsd:string" />
<xsd:element name="MetaID" type="xsd:string" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>

<!-- Element declaraction (may be local). -->
<xsd:element name="MetaData" type="MetaDataType" />

- - -

Admittedly, the redundancy in the sequence is something we want to
avoid. The presence of such repetition in a schema is an opportunity
for error because it creates two sequences that demand synchronized
maintenance when revising the schema. What can be done?

Fortunately XML Schema furnishes the group construct for composing
a global model that can be referenced from within type definitions. Think
of a group as short-hand for the model that it defines, an alias-of-sorts.

Here's how the schema looks,

- - - MetaData2.xsd (excerpt)
<!-- Define the group globally. -->
<xsd:group name="MetaDataCoreGroup" >
<xsd:sequence>
<xsd:element name="CreaDate" type="xsd:string" />
<xsd:element name="CreaTime" type="xsd:string" />
<xsd:element name="SyncOnce" type="xsd:string" />
<xsd:element name="SyncTime" type="xsd:string" />
<xsd:element name="ModDate" type="xsd:string" />
<xsd:element name="ModTime" type="xsd:string" />
</xsd:sequence>
</xsd:group>

<!-- Define the MetaData type as above, but referencing the group. -->
<xsd:complexType name="MetaDataType">
<xsd:choice>
<xsd:sequence>
<xsd:element name="MetaID" type="xsd:string" />
<xsd:group ref="MetaDataCoreGroup" />
</xsd:sequence>
<xsd:sequence>
<xsd:group ref="MetaDataCoreGroup" />
<xsd:element name="MetaID" type="xsd:string" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>

<xsd:element name="MetaData" type="MetaDataType" />

- - -

As you can see, this strongly types the MetaID whether it appears at
the top or bottom of the children of the MetaData element. This turns
out to be better than ignoring the element (in which case the schema
would give up on trying to identify what element is there, and potentially
incorrect instance documents may be regarded as schema-valid); and
its something that XML Schema supports without duplication of the
content model, which is vital in large schema that must be maintained.
Derek Harmon
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Martin Danielson | last post by:
I have a problem that I can't work out. I have a script in ASP using VBScript that act quite funny when editing and xml file. Here is my explenation I have the following xml-fil <root><element...
0
by: Peter Aberline | last post by:
Hi all, I'm trying to write a schema which defines the following document. <root> <letters> <a>A</a> <dog>DOG<dog> <b>B</b> <fish>FISH</fish>
29
by: Joseph Haig | last post by:
I am trying to use descriptive lists, <DL>, as shown in <http://www.maths.man.ac.uk/~jhaig/tmp/test.html> with a style sheet at <http://www.maths.man.ac.uk/~jhaig/tmp/default-2.css>. With Mozilla...
2
by: kevin_Eld | last post by:
I have the following xml: <message> <envelope> <body key="" value="" /> </envelope> </message> I have associated an xsd to this xml in order to use the XmlDataDocument and give me the
3
by: rob.guitar.rob | last post by:
Hello, My last few posts have been revolving aroung the same problem, and I still cant solve it and I would be really appreciate if anyone could spot a problem. a section of my XML goes like...
1
by: davis | last post by:
Hello, I am working in .Net C# and have an xml file similar to the one below. I have tried using a DataSet but get the error "The same table (Gid) cannot be the child table in two nested...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: emzipoo4u | last post by:
Hi, I am creating an XML document with ASP (new to XML). I would like to know how do i add details to a tag e.g. i want to generate <Order xmlns="urn:www.badjda.org/schema/test_order_v3.00.xml">...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.