473,406 Members | 2,312 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,406 software developers and data experts.

How to allow arbitrary content but make one requirement

Hi,

I have a schema which is fine except for one part giving me trouble:

(...)

<xs:element name="DOC">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any processContents="lax" minOccurs="0"
maxOccurs="unbounded" />
<xs:element ref="IEOutput" minOccurs="1" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="ADEPTID" type="xs:string" use="required" />
<xs:anyAttribute processContents="lax" />
</xs:complexType>
</xs:element>

(...)
I get the error: "The content model must be deterministic. Wildcard
declaration along with a local element declaration causes the content
model to become ambiguous."

I can see how at validation-time it is ambiguous whether the <xs:any>
or <xs:element> particle should be responsible for covering a given
<IEOutput> element (which I guess means XML processors aren't
responsible for things like backtracking).

My question is this: how do I say in a schema that "you can have any
number of arbitrary children so long as one of them conforms to the
(elsewhere defined) <IEOutput> element particle"? What I really mean
by "one of them" is "exactly one" but I'd also settle for "at least
one". And I also have a requirement that the <IEOutput> element should
come last, but I could drop that req'ment too.
Thanks
Mike
Nov 11 '05 #1
1 2717

Hi,

<<My question is this: how do I say in a schema that "you can have any
<<number of arbitrary children so long as one of them conforms to the
<<(elsewhere defined) <IEOutput> element particle"?

You cannot without being non-deterministic if the required element and the
other elements are in the same schema namespace, and the .NET and MSXML
schema processors do not permit non-deterministic schemas.

What you can do is define the required element in a disctinct schema
namespace...

reqElem.xsd:

<?xml version="1.0" standalone="yes"?>
<xs:schema xmlns="urn:test" targetNamespace="urn:test"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="RequiredElement" type="xs:string"/>
</xs:schema>

... and in the main schema define the complexType sequence content model as
comprising of 2 xs:any definitions. For the second any element set the
minOccurs and maxOccurs to 1 and the namespace attribute to the namespace
of the schema that defines the required element. Since this namespace
defines only one element, the instance documents must contain it dues to
the min and max occurs contraints defined on the any element. For the first
any element set minOccurs = 0, maxOccurs = "unbounded" and the namespace
attribute to a list of namespaces excluding the namespace in which you
defined the required element that must appear only once. If you ommit the
namespace attribute... the default will be ##any which implies that
multiple occurences of the "once only" required element can then occur.
Sample schema based on the above schema that defines the required element
is provided below. Note that this will also address your requirement of the
requirement element being the last element in the sequence:

data.xsd:

<?xml version="1.0" standalone="yes"?>
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:r="urn:test">

<xs:import namespace="urn:test" schemaLocation="reqElem.xsd"/>

<xs:element name="elem1" type="xs:string"/>
<xs:element name="elem2" type="xs:string"/>

<xs:element name="MyElement">
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"
namespace="##local"/>
<xs:any processContents="lax" minOccurs="1" maxOccurs="1"
namespace="urn:test"/>

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

The following is a sample instance document that will validate successfully
against the above schema:

<MyElement xmlns="" xmlns:r="urn:test">
<elem1>data</elem1>
<elem2>data</elem2>
<r:RequiredElement>data</r:RequiredElement>
</MyElement>

The following is a sample instance that will fail validation as the
required element is not the last element in the sequence:

<MyElement xmlns="" xmlns:r="urn:test">
<elem1>data</elem1>
<r:RequiredElement>data</r:RequiredElement>
<elem2>data</elem2>
</MyElement>

Hope this helps.

Thanks
Karthik

This posting is provided "AS IS" with no warranties and confers no rights.

Nov 11 '05 #2

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

Similar topics

24
by: Mohammd M. Hussain | last post by:
Hi, I am writing an XHTML 1.0 Strict Compatible web page. However, the validator complained about the <br> tag. I wonder whether there is another alternative for this. Thanks,
8
by: Steve Neill | last post by:
Can anyone suggest how to create an arbitrary object at runtime WITHOUT using the deprecated eval() function. The eval() method works ok (see below), but is not ideal. function Client() { }...
7
by: Andrew Robinson | last post by:
Given HTML text (likely from SQL), is there any method that could be employed to render server and/or custom controls that are contained inside of that text? I would be loading content from a...
20
by: quantumred | last post by:
I found the following code floating around somewhere and I'd like to get some comments. unsigned char a1= { 5,10,15,20}; unsigned char a2= { 25,30,35,40}; *(unsigned int *)a1=*(unsigned int...
6
by: JM | last post by:
I have never used a (content management system) CMS before but I need one for my internship as a webdeveloper. Requirements: runs on Apache, linux or unix, MySQL and PHP (maybe Windows server...
5
by: visu | last post by:
Hi this is a question asked in this group two years back.. No answer for this question till date. now i am in the same situation of the questioner.. to find a solution for this problem. Can any...
4
by: Eric | last post by:
Attached is an example of my question. Note the "values" attribute is optional. Also the <valuesub-element is optional. Here, the XML can contain, 1 or both or neither. I would like to allow...
3
by: John Kotuby | last post by:
Hi all, Just wondering why this would happen. I had created a standalone ASPX page in which 5 controls are wrapped in an UpdatePanel. The idea is Control1 selection populates Control2 then...
4
by: Steven Simpson | last post by:
Stefan Ram wrote (in "More than one language in a page"): Is this a new trend of user-agent writers (Microformats, and now Google) staking claims on the @class namespace? I'm surely not the only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.