473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XML Schema - variable number of elements?

I have an XML element <val> with child elements. I'd like to be able to include any of the child elements, or leave them out, without having to write default null values each time for unneeded children... example out of the 12 available child elements i may only need 2 for a particular instance of <val>, 1 for another and 3 for another ...

XML e.g.

Expand|Select|Wrap|Line Numbers
  1. <validation tag="applet">
  2.   <val>
  3.     <hasAttr>alt</hasAttr>
  4.     <hasNodeText>yes</hasNodeText>
  5.   </val>
  6. [...]  
  7.   <val>
  8.     <hasNodeText>yes</hasNodeText>
  9.   </val>
  10. </validation>
  11.  
but i can't figure out how to declare elements in the schema to be able to use any combination of them in xml file... with xs:sequence, or xs:all or xs:choice (???)

can it be done?

part of the schema code is below.


Expand|Select|Wrap|Line Numbers
  1. <xs:element name="val" maxOccurs="unbounded">
  2.   <xs:complexType>
  3.     <xs:all>  <!--  ?????    -->
  4.  
  5.       <xs:element name="manualCheck" type="xs:integer" />
  6.       <xs:element name="hasAttr" type="xs:string" />
  7.       <xs:element name="hasNodeText" type="xs:string" />
  8.       <xs:element name="containedIn" type="xs:string" />
  9.       <xs:element name="hCheckFollowedBy" type="xs:string" />
  10.       <xs:element name="relativeValue" type="xs:string" />
  11.       <xs:element name="hasEventScript" type="xs:string" />
  12.       <xs:element name="ifHasExtension" type="xs:string" />
  13.       <xs:element name="raiseError" type="xs:integer" />
  14.       <xs:element name="valDesc" type="xs:string" />
  15.  
  16.       <xs:element name="lookForTag">
  17.         <xs:complexType>
  18.           <xs:simpleContent>
  19.             <xs:extension base="xs:string">
  20.               <xs:attribute name="position" type="xs:string" />
  21.               <xs:attribute name="top" type="xs:string" />
  22.               <xs:attribute name="attribute" type="xs:string" />
  23.               <xs:attribute name="value" type="xs:string" />
  24.             </xs:extension>
  25.           </xs:simpleContent>
  26.         </xs:complexType>
  27.       </xs:element>
  28.  
  29.     </xs:all>
  30.   <xs:complexType>
  31. </xs:element>
  32.  
(if the above example is not clear, here's a simpler similar example... imagine an HTML sentence which can have <i>, <b> and <u>. Each sentence can have just one of them, none, or any combination of the 3 elements... and I need a way of how to show this in the schema!!)


thanks...
Sep 17 '07 #1
1 3212
may have found a solution...
left <xs:all> there so that I can use the elements in any order, and added a minOccurs="0" to each element to allow me not to include the element...

Expand|Select|Wrap|Line Numbers
  1. <xs:element name="manualCheck" type="xs:integer" minOccurs="0"/>
does it make sense?
(The XML Instance file validated against this schema now)
Sep 17 '07 #2

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

Similar topics

7
by: Gili Korman | last post by:
Hi all, I need to create an XSD schema that will reperesent the following: <LIST> <ITEM1/> 0-unbounded <ITEM3/> 0-unbounded </LIST> or
2
by: Mark Constant | last post by:
All I want to do is have a xml file like this <Entertainment> <Movie> <Title>(Title Here)</Title> <Rating>(Rating Here)</Title> </Movie> <Movie> <Title>(Title Here)</Title> <Rating>(Rating...
0
by: Lindy | last post by:
I have a schema file called Asc.xsd which I have added to my .Net project (VB). I am using XMLTextWriter in order to create/write data to a new XML file. How can I access the elements, etc....
2
by: mrc-1 | last post by:
Hi, i'd like to validate my XML file (see below) using XML Schema. Now my question: is it possible to limit the occurrence of the element b in the data element. I mean: data can contain up to...
1
by: Chris Lieb | last post by:
I am new to XML Schema and am running into a bit of a snag. I have defined an XML-based scripting language for an updater program that I am working on. I would like to make a schema for this...
5
by: Damiano ALBANI | last post by:
Hello, I'd like to write a single XML Schema for both these documents : <Items> <Item xml:id="id1"> <Name>ABC</Name> ... </Item> <Item xml:id="id2">
5
by: paul_zaoldyeck | last post by:
does anyone know how to validate an xml file against multiple defined schema? can you show me some examples? i'm making here an xml reader.. thank you
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
4
by: ashish.sadanandan | last post by:
Hi, I'm new to XML and just started reading some documentation on W3C compliant schemas recently. The XML file I'm generating is for an embedded application and so size is of extreme importance....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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
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...

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.