473,769 Members | 5,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:complexTy pe mixed="true">
<xs:sequence>
<xs:any processContents ="lax" minOccurs="0"
maxOccurs="unbo unded" />
<xs:element ref="IEOutput" minOccurs="1" maxOccurs="1" />
</xs:sequence>
<xs:attribute name="ADEPTID" type="xs:string " use="required" />
<xs:anyAttribut e 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 2764

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="RequiredE lement" 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:te st">

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

<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="unbo unded"
namespace="##lo cal"/>
<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:te st">
<elem1>data</elem1>
<elem2>data</elem2>
<r:RequiredElem ent>data</r:RequiredEleme nt>
</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:te st">
<elem1>data</elem1>
<r:RequiredElem ent>data</r:RequiredEleme nt>
<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
5836
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
3193
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() { } Client.prototype.fullname = "John Smith"; var s = "Client"; eval("var o = new " + s + "();"); alert(o.fullname);
7
1505
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 database and would like to 'expand' the server controls. Possibly even recursively. Hope this makes sense, but I am guessing the answer is no. If this is something that can't be done, I am looking at creating my own markup tags and searching for...
20
3530
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 *)a2; // now a1=a2, a1=a2, etc.
6
3151
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 and IIS) Authentication (not sure yet): existing user database, LDAP or permissions on directories (not sure if that last one is possible) Purpose: scientist working on projects should be able to upload their
5
3978
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 one help me in this regard.? The question is: ---------------------------------------------------------------------------------------------------- Wondering if anyone can tell me if it's possible to have Javascript
4
2709
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 EITHER the "values" attribute or <valuesub-elements - but not both. I tried using a <choicewith two element definitions for "characteristic" with different content, but this is clearly not allowed in XSD. Does anyone have an answer? Thanks.
3
2368
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 Control2 populates Control3, all depending upon which selection the user makes in each contol. For example the Ctrl1 is a DataList. A selection there populates a 3rd party Grid Control. Selection of a Grid row populates a MultiView control. It was...
4
3017
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 one disturbed by this. Somehow, an author publishing on the web, with no control over which user agents will access his page, has to avoid clashes with the union of all names deemed special by all those user agents, now and in the future? I...
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.