473,503 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Schemas Question

Hi,

I am still a newbie with XML and was hoping someone could help me with
this query. I want to create an XML Schema that would allow me to have
two elements that have a different structure in two different areas of
XML. It's probably easier if I provide a sample XML :-

<MyXML>
<MDP type="MDP">
<linkFactor type="linkFactor">
<value type="decimal">0.9</value>
</linkFactor>
</MDP>
<MDS type="MDS">
<linkFactor type="linkFactor">0.90</linkFactor>
</MDS>
</MyXML>

Basically, in the above sample linkfactor is present twice, but in the
MDP section I want it to have a value tag.

Is it possible to create an XML Schema to correspond to this ?
I was thinking I need to hide the definitions of linkfactor so that I
have two one for each element. My thoughts of what the actual schema
defn. of this type would be

<xs:complexType name="linkFactorType" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="value" type="valueType"/>
</xs:choice>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>

for the expanded version that includes the value tag and

<xs:element name="linkFactor" type="linkFactorType"/>

for the simpler type. Just confused on how to pick-up one defn over the
other.
Any guidance greatly appreciated.

Many Thanks,
Ab

Jul 20 '05 #1
2 1189
Hi Ab,

You would need a separate complex type definition for the "simpler"
linkFactor, something like this:

<xs:complexType name="linkFactorType2">
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

Then, you would declare the two linkFactor elements locally with
different types, depending on which parent definition they are in. For
example:

<xs:element name="MDP" type="MDPType"/>
<xs:complexType name="MDPType">
<xs:sequence maxOccurs="unbounded">
<xs:element name="linkFactor" type="linkFactorType"/>
</xs:sequence>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>

and

<xs:element name="MDS" type="MDSType"/>
<xs:complexType name="MDSType">
<xs:sequence maxOccurs="unbounded">
<xs:element name="linkFactor" type="linkFactorType2"/>
</xs:sequence>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
Hope that helps,
Priscilla
----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
Thanks Priscilla. This exactly does what I'm after.

Cheers.
Abu

Jul 20 '05 #3

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

Similar topics

1
1227
by: Jon Sequeira | last post by:
I have a question about a general approach to mapping schemas for use with SQLXML . Suppose I have a product table, which has information that's related to two groups of otherwise unrelated...
5
1420
by: rox.scott | last post by:
The following article says the .NET SOM will not allow what it calls "non-deterministic" schemas...
2
1270
by: John Jenkins | last post by:
Hi, I have a lot of schemas to load into a schema collection. I load them in by reading each one into a XMLTextReader from disk and add them into a schema collection. I have a couple of issues to...
4
1376
by: AndrewDucker | last post by:
(Posted to microsoft.public.xml originally, then realised this was a better place for it) I've got three schemas I'm trying to add to a schemacollection so that I can validate a series of...
3
1282
by: Modica82 | last post by:
Hi All, I am in the process of designing a web service for my company. It is my first commercial web service, so i think my "Hello World" coding model wont quite cut it here :). Anyway, i am...
3
4616
by: Sami Marzouki | last post by:
Hi, What I'm trying to do is: - To write a Web.config with custom sections. (Done) - To write a xsd schema for this custom sections.(Done) - Tell the Web.config to take the two schemas. When...
0
1802
by: vihrao | last post by:
I am designing wsdl that uses multiple schemas. I can do this in two ways: 1) use multiple schema imports in one wsdl or 2) use multiple schema imports in to one common schema and then import a...
2
3064
by: Darrell Plank | last post by:
I'm a real XML novice, but my ultimate goal here is to get a workable schema for the GEDCOM XML format as spec'ed out here: http://www.familysearch.org/GEDCOM/GedXML60.pdf It's a proposed XML...
1
1145
by: Piotrekk | last post by:
Hi I was reading a lot about DataSets and XML schemas ( xsd ) None of the sources has answered my question - when should we use schemas? Usually when i save and load dataset to/from XML I don't...
3
3644
by: Water Cooler v2 | last post by:
Sorry for asking this beginner question. I've written DTDs so far and read about XML Schemas. I understand that they are a replacement of the DTD fundamentally, and therefore allow for the...
0
7207
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
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7357
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...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
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
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.