472,958 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1733
"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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.