473,394 Members | 1,840 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 Q: Element with either simpleContent or complexContent

How can I create an xml schema where both of the following documents
are valid?

<theElement>
<child>some text</child>
</theElement>

and

<theElement>1234</theElement>

Basically, <theElement> should either contain a single element <child>
of a specified type or an integer.

Thanks,
David
Jul 20 '05 #1
3 1935


David Norman wrote:
How can I create an xml schema where both of the following documents
are valid?

<theElement>
<child>some text</child>
</theElement>

and

<theElement>1234</theElement>

Basically, <theElement> should either contain a single element <child>
of a specified type or an integer.

If you use

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="theElement" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="theElement">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="child" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

that is you specify the element to have a complex type where mixed
content is allowed then the following validates:

<?xml version="1.0" encoding="UTF-8"?>
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2004073101Xsd.x ml">
<theElement>
<child>some text</child>
</theElement>
<theElement>1234</theElement>
</root>

However the schema also allows a <theElement> as follows
<theElement>1234<child>Kibology</child>1234</theElement>

If you want to allow either the simple content of type integer or a
complex content of exactly one child element you would need to have a
union of both types however I think a union is only possible for simple
types.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41******@olaf.komtel.net>...
David Norman wrote:
How can I create an xml schema where both of the following documents
are valid?

<theElement>
<child>some text</child>
</theElement>

and

<theElement>1234</theElement>

Basically, <theElement> should either contain a single element <child>
of a specified type or an integer.

If you use

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="theElement" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="theElement">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="child" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

that is you specify the element to have a complex type where mixed
content is allowed then the following validates:

<?xml version="1.0" encoding="UTF-8"?>
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2004073101Xsd.x ml">
<theElement>
<child>some text</child>
</theElement>
<theElement>1234</theElement>
</root>

However the schema also allows a <theElement> as follows
<theElement>1234<child>Kibology</child>1234</theElement>

If you want to allow either the simple content of type integer or a
complex content of exactly one child element you would need to have a
union of both types however I think a union is only possible for simple
types.


Because of the last possibility, mixed="true" doesn't give me what I want.

Thanks,
David
Jul 20 '05 #3
David Norman wrote:
How can I create an xml schema where both of the following documents
are valid?

<theElement>
<child>some text</child>
</theElement>

and

<theElement>1234</theElement>

Basically, <theElement> should either contain a single element <child>
of a specified type or an integer.


This sounds to me like extremely poor data design.

///Peter
--
"The cat in the box is both a wave and a particle"
-- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gehirnloser Zombie | last post by:
Hello folks, Short question: Is it possible to express with XML-Schema that for an element some attributes may apear only disjunctivly (i.e. an element <E> can either carry the attribute "a1" OR...
1
by: Alex Sab | last post by:
Hi, I am having trouble describing in a schema that elements can be mandatory in one part and not mandatory in another part of the xml document. Here is a sample xml file <Model:Templates>...
2
by: inquirydog | last post by:
I am trying to store my computer network information in an xml file, and plan to write an xml schema for the file. The general format of the xml should be like this <networkinfo>...
2
by: John Carron | last post by:
Hi All, I have written a simple schema (see below) that uses substitution groups. I don't know if this the correct usage because I'm fairly new to xml schema. The structure is as follows: ...
1
by: David Laub | last post by:
The following valid XSD schema can NOT be successfully read by the ReadXMLSchema method of the DataSet object - it errors out with a "NonEmptyString not defined" error. This schema is more complex...
1
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i...
4
by: olivier.scalbert | last post by:
Hello, I need to create an xsd to validate the following type of xml: <?xml version="1.0" encoding="UTF-8"?> <root <exception1 xsi:type="ExceptionAType"> <Type>1</Type> <Info>Bla bla</Info>...
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
0
by: icesign | last post by:
I know that the selector of these elements has a scope relative to the element being declared, but maybe there is a way to get beyond bounds of this scope or maybe just a way to extend base element?...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.