Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 9th, 2008, 02:11 PM
Authorized User
Join Date: Oct 2006
Location: , , .
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Optional element exists if has inner elements

  How do I make an optional element to not exist if it has no inner elements?

For example, I have the following snippet of XML schema:

<xs:element name="Box" type="myXml:BoxType" minOccurs="0" maxOccurs="1"/>

<xs:complexType name="BoxType">
    <xs:element name="Ball" type="xs:string" minOccurs="0" maxOccurs="1"/>
    <xs:element name="Pen" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>

1st XML example:

2nd XML example:

   In the 2nd example, because <Box> element has no inner elements, I like <Box> element to not exist at all. How do I modify the above XML schema to do that? I like <Box> element to exist if it has at least 1 inner element, else no <Box> element at all.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
Inserting into a tree with optional elements iceandrews XSLT 2 April 24th, 2008 08:59 AM
Access specific Element and its Child elements! suersh79 XML 3 November 22nd, 2006 12:58 AM
how to control optional elements and attributes NEO1976 XSLT 5 September 4th, 2006 02:58 AM
putting <element> round group of same elements jefke XSLT 0 May 24th, 2004 10:18 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.