Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD array type structure with multiple data types

Status
Not open for further replies.

ace333

Programmer
Jul 12, 2005
105
CH
***********************************************************

<?xml version="1.0" encoding="ISO-8859-1"?>

<testXML xmlns:xsi = " xsi:noNamespaceSchemaLocation = "testXSD.xsd">


<proc>


<nameOf> testName </nameOf>

<param>2005</param>

<param>test</param>

</proc>

</testXML>
*******************************************************


<?xml version="1.0" encoding="ISO-8859-1" ?>


<xs:schema xmlns:xs="
<xs:element name="testXML">


<xs:complexType>
<xs:sequence>

<xs:element name="proc">

<xs:complexType>

<xs:sequence>

<xs:element name="nameOf" type="xs:string"/>

<xs:choice>


<xs:element name="param" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>

<xs:element name="param" type="xs:double" minOccurs="1" maxOccurs="unbounded"/>

</xs:choice>





</xs:sequence>
</xs:complexType>
</xs:element>

</xs:sequence>
</xs:complexType>

</xs:element></xs:schema>

Above is an xml file and the corresponding xsd file except for the fact that the param element in the xsd is defined twice. Basically what I want to do is create an array type structure where is the value between <param> in the xml is a string it will be detected as a string by the xsd and if its an int detected as an int and so on if i included floats or doubles etc. I saw this choice method on the web but it does not work because you cannot declare the param element twice in the same code.
Here is my dilema, I would like to be able to validate the following:
<param>2005</param>

<param>test</param>

<param>2.4</param>

where param can be any type of datatype so if its a string is goes to the string xsd or the int and so on.

Hopefully that made sense, I'll continue to probe anyway,cheers - Ace333.
 
I don't really understand the question. If your param can be anything, why not just use xs:string?

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
What I mean is

if param is the following

<param>10</param>
<param>String</param>
<param>True</param>
<param>0.54</param>

So if the value in param is a string its treated as a string, if its an int its treated as an int. I'm wondering if there is a way to deal with this in the xsd. At the moment it wont allow multiple param values unless they are of the same type ...
 
What do you mean by "treated"? Schema's don't do any processing, they simply validate the XML. If you can have a param that is a string, you can have a param which is anything.

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
How stupid do I feel write now ? Thanks (embarressed)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top