473,323 Members | 1,550 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,323 software developers and data experts.

Multiple occurrences of an xml element

Hi,

I want to be able to represent the following xml in a schema

<Data>
<a/>
<b/>
<c subtype='one value'/>
<c subtype='another value'/>
<d/>
etc.
</Data>

Further constraints are (a) in real world, elements may appear in any
order (which appears to constrain me from using sequence), (b) although
several elements are optional, I cannot guarantee that only one element
will be present at any one time (which appears to constrain me from
using choice).

My gut feel is that I should be using <xs:all>, but in an <xs:all>
maxoccurs may not be greatee than one. So, when I throw a document at a
schema, the second occurrence of element c makes the document invalid.

Am I missing something? This seems like an obvious question, but....

I would be happy to approach this differently if anyone has any ideas -
the constraints are as above, and I really do want to run the data file
through a schema before I waste any time processing it.

TIA,
Pete
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
1 2620


Pete wrote:

I want to be able to represent the following xml in a schema

<Data>
<a/>
<b/>
<c subtype='one value'/>
<c subtype='another value'/>
<d/>
etc.
</Data>

Further constraints are (a) in real world, elements may appear in any
order (which appears to constrain me from using sequence), (b) although
several elements are optional, I cannot guarantee that only one element
will be present at any one time (which appears to constrain me from
using choice).

My gut feel is that I should be using <xs:all>, but in an <xs:all>
maxoccurs may not be greatee than one. So, when I throw a document at a
schema, the second occurrence of element c makes the document invalid.

Am I missing something? This seems like an obvious question, but....


I think you need to use
<xs:choice minOccurs="0" maxOccurs="unbounded">
as in the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="Data" type="DataType" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="DataType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="a" />
<xs:element name="b" />
<xs:element name="c" />
<xs:element name="d" />
</xs:choice>
</xs:complexType>

</xs:schema>

That way it is possible that you have zero child elements in <Data> or
several ones and order doesn't matter.

For instance the following instance validates here against that schema
with both MSXML 4 and Xerces-J:

<?xml version="1.0" encoding="UTF-8"?>
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2004112701Xsd.x ml">
<Data>
<a/>
<b/>
<c />
<c />
<d/>
</Data>
<Data>
</Data>
<Data>
<b/>
<c />
<c />
<d/>
<a/>
</Data>
</root>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2

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

Similar topics

0
by: Adam Smith | last post by:
Hello. I've got a total of 5 schemas. They are: 1 - 1.xsd - a description of a city 2 - 2.xsd - a description of a town 3 - CityHall.xsd - a description of a cityhall-meant to be part of a...
5
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
1
by: STA | last post by:
Hi. Given this XML: <itemdata> <item> <itemid>10</itemid> <ctid>1</ctid> </item> <item> <itemid>11</itemid>
3
by: jparulan | last post by:
Hi All, I'm using SOAP3.0. I was able to successfully call a WSDL file and get a value properly. But when the WSDL changed to have a MULTIPLE <element name> it was failing. This code works...
5
by: paul_zaoldyeck | last post by:
does anyone know how to validate an xml file against multiple defined schema? can you show me some examples? i'm making here an xml reader.. thank you
2
by: mavis | last post by:
Could you please help me with this xsd definition? I need to define a set of elements occur in any order with multiple occurrences, but the same kind of elements need to group together... Sth...
4
by: Nick Vargish | last post by:
Hi, I'm a little bit stuck trying to send a SOAP request that includes multiple occurrences of an element. For the sake of illustration, this is what the relevant portions of the SOAP request...
7
by: redman08 | last post by:
I have a problem as follows:I have a form, with fields to edit. The data is keyed on a 'text identifier', which is entered and then used. I then determine if there are multiple occurrences of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.