DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Posts
    2

    xsd: one of two childelements required, no repetition

    Hi all

    I'm looking for a shema solution since a while. The idea is to have one parent element which stores 2 elements of different name. At least one of them must occur, but it is not defined which. It must not be possible to repeat one element twice (child1 should occurs maximum once).

    My idea is something like this:
    Code:
    <xs:element name="parent">
    	<xs:complexType>
    		<xs:sequence>
    			<xs:choice maxOccurs="2">
    				<xs:element name="child1" minOccurs="0"/>
    				<xs:element name="child2" minOccurs="0"/>
    			</xs:choice>
    		</xs:sequence>
    	</xs:complexType>
    </xs:element>
    Generating a sample xml with XMLSpy shows, that this doesn't work.
    Code:
    <parent>
    	<child1>text</child1>
    	<child1>text</child1>
    </parent>
    Wrong in the example xml is:
    it is
    • possible to repeat child1 (or child2) two times
    • it is possible to declare a parent without child elements

    Do you have an idea how to solve this problem?

    Thank you.

    Kind regards

  2. #2
    Join Date
    Nov 2008
    Posts
    2

    solution with dtd

    I've found a solution using a dtd. Do you know a way how to do this with a shema?

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE grandparent [ 
    	<!ELEMENT grandparent (parent*)> 
    	<!ELEMENT parent (child1 | child2 | (child1,child2))> 
    	<!ELEMENT child1 (#PCDATA)> 
    	<!ELEMENT child2 (#PCDATA)> 
    ]> 
    <grandparent>
    	<parent>
    		<child1>text</child1>
    	</parent>
    	<parent>
    		<child2>text</child2>
    	</parent>
    	<parent>
    		<child1>text</child1>
    		<child2>text</child2>
    	</parent>
    </grandparent>

Similar Threads

  1. C++,Unix Professionals required for CADENCE India
    By sapphirecs in forum Careers
    Replies: 0
    Last Post: 12-06-2006, 01:36 PM
  2. entity references in XSD definitions?
    By unknown in forum XML
    Replies: 0
    Last Post: 04-02-2002, 11:15 AM
  3. Replies: 1
    Last Post: 09-07-2001, 03:03 PM
  4. Replies: 1
    Last Post: 09-07-2001, 03:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links