Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Schemas Question

Reply
Thread Tools

XML Schemas Question

 
 
abu123
Guest
Posts: n/a
 
      02-21-2005
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

 
Reply With Quote
 
 
 
 
Priscilla Walmsley
Guest
Posts: n/a
 
      02-21-2005
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!
 
Reply With Quote
 
 
 
 
abu123
Guest
Posts: n/a
 
      02-21-2005
Thanks Priscilla. This exactly does what I'm after.

Cheers.
Abu

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can xml schemas from a dataset be used to validate standard xml files? Andy B ASP .Net 0 08-06-2008 11:42 PM
Help with Kalani 70-320 Training Guide question on XML schemas Pookee MCAD 1 09-29-2004 04:27 PM
Strange problem with JDOM, Xerces and XML Schemas Soeren Java 2 09-22-2004 10:17 AM
Question about attribute inheritence in XML Schemas using <xsd:extension> Sean Bright XML 2 12-17-2003 11:51 PM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments