XML Schemas Question

A

abu123

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
 
P

Priscilla Walmsley

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top