468,268 Members | 1,970 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

having difficulties with 'choice'

3
Hi,

I'm currently busy writing an xsd at one point in time i whish that my xml must look like:
Expand|Select|Wrap|Line Numbers
  1. <object>
  2.     <loc>
  3.         <disk>
  4.             <drive>c</drive>
  5.             <path>temp\path</path>
  6.             <files>*.*</files>
  7.         </disk>
  8.     </loc>
  9.     <interval>
  10.         ...
  11.     </interval>
  12. </object>
or (choice)
Expand|Select|Wrap|Line Numbers
  1. <object>
  2.     <loc>
  3.         <network>
  4.             <server>localhost</server>
  5.             <path>temp\path</path>
  6.             <files>*.*</files>
  7.         </network>
  8.     </loc>
  9.     <interval>
  10.         ...
  11.     </interval>
  12. </object>
  13.  
or (another choice)
Expand|Select|Wrap|Line Numbers
  1. <object>
  2.     <loc>
  3.         <internet>
  4.             <uri>123.456.789.123</uri>
  5.             <path>temp\path</path>
  6.             <files>*.*</files>(optional (if webservice))
  7.             <port>8888</port>(optional)
  8.                 ....
  9.         </internet>
  10.     </loc>
  11.     <interval>
  12.         ...
  13.     </interval>
  14. </object>
  15.  
so the <loc> tag can contain (in my case) 5 different objects, which are all locations of some sorts. But the <loc> tag may only contain one (complex) child, which can be either an <internet>tag, a <network> tag or a <disk> tag.

How to get to my question: How do I pull this off in my XSD?

This is what I tried:
Expand|Select|Wrap|Line Numbers
  1. <xs:complexType name="Location">
  2.     <xs:sequence maxOccurs="1" minOccurs="1">
  3.         <xs:choice maxOccurs="1" minOccurs="1">
  4.             <xs:element name="localDisk" type="LocalDisk" maxOccurs="1" minOccurs="0" />
  5.             <xs:element name="networkLocation" type="NetworkLocation" maxOccurs="1" minOccurs="0" />
  6.             <xs:element name="internetSite" type="InternetSite" maxOccurs="1" minOccurs="0" />
  7.             <xs:element name="secureInternetSite" type="SecureInternetSite" maxOccurs="1" minOccurs="0" />
  8.             <xs:element name="ftpSite" type="FtpSite" maxOccurs="1" minOccurs="0" />
  9.         </xs:choice>
  10.     </xs:sequence>
  11. </xs:complexType>
  12.  
  13. <xs:complexType name="TextDataProvider">
  14.     <xs:sequence>
  15.         <xs:element name="location" type="Location" maxOccurs="1" minOccurs="1" />
  16.         <xs:element name="interval" type="Interval" maxOccurs="1" minOccurs="1" />
  17.         <xs:group ref="textSchema" maxOccurs="1" minOccurs="1" />
  18.     </xs:sequence>
  19.     <xs:attributeGroup ref="Identification" />
  20. </xs:complexType>
  21.  
  22. <xs:complexType name="Configuration">
  23.     <xs:sequence>
  24.         <xs:choice maxOccurs="3" minOccurs="1">
  25.             <xs:element name="textProviders" maxOccurs="unbounded" minOccurs="1" type="TextDataProviders" />
  26.             <xs:element name="csvProviders" maxOccurs="unbounded" minOccurs="0" type="CsvDataProviders" />
  27.             <xs:element name="xmlProviders" maxOccurs="unbounded" minOccurs="0" type="XmlDataProviders" />
  28.         </xs:choice>
  29.     </xs:sequence>
  30. </xs:complexType>
  31.  
  32. <xs:element name="configuration" type="Configuration"></xs:element>
  33.  
  34. <xs:complexType name="TextDataProviders">
  35.     <xs:sequence>
  36.         <xs:element name="dataprovider" type="TextDataProvider" minOccurs="0" maxOccurs="unbounded" />
  37.     </xs:sequence>
  38. </xs:complexType>
  39.  
But that doesn't do the trick, because when I'm forming an xml based on this xsd I can add as many locations of any kind within the location tag

I must be doing something wrong, I just can't see it at this time.

With kind regards,
- SL33PY
May 10 '06 #1
1 1269
SL33PY
3
I've been thinkering a bit, as well as reading some additional sources and I made a temp xsd and xml:

The temp xsd:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <xs:schema targetNamespace="XMLSchema1.xsd" elementFormDefault="qualified" xmlns="XMLSchema1.xsd"
  3.     xmlns:mstns="XMLSchema1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  4.     <xs:element name="Configuration">
  5.         <xs:annotation>
  6.             <xs:documentation>
  7.                 This tag describes the configuration of the system.
  8.                 It consists of maximum 3 childs representing the different kinds of
  9.                 providers that our application can process. Every child represents a group
  10.                 of data providers of a specific kind.
  11.             </xs:documentation>
  12.         </xs:annotation>
  13.         <xs:complexType>
  14.             <xs:choice minOccurs="1" maxOccurs="3">
  15.                 <xs:element name="TextProviders" maxOccurs="1" minOccurs="0" type="xs:string" /><!--type="TextProvidersType" />-->
  16.                 <xs:element name="CsvProviders" maxOccurs="1" minOccurs="0" type="xs:string" /><!--type="CsvProvidersType" />-->
  17.                 <xs:element name="XmlProviders" maxOccurs="1" minOccurs="0" type="xs:string" /><!--type="XmlProvidersType" />-->
  18.             </xs:choice>
  19.         </xs:complexType>
  20.     </xs:element>
  21. </xs:schema>
The temp xml:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Configuration xmlns="XMLSchema1.xsd">
  3.     <CsvProviders></CsvProviders>
  4.     <TextProviders></TextProviders>
  5.     <XmlProviders></XmlProviders>
  6. </Configuration>
  7.  
at this moment it works, but...

I adjusted my older xsd file and the xsd gets validated, still I cannot select it from the list (VS 2003) in the targetnamespace property field, I can select the xmlschema1.xsd but not my bigger one :confused:

I'll expand this test xsd and perhaps I can find out why the other doesn't work as intended. If anyone has hints/tips/more insight, please let me know asap

- SL33PY
May 10 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by James Bright | last post: by
9 posts views Thread by Jordan Tiona | last post: by
3 posts views Thread by jg.campbell.ng | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.