473,804 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Semi-unique IDs in Schema

How do I define that the contents of an element should be unique only in
a sub-tree of the whole XML file?

In my case, I have several documents, each containing several files. The
file names have to be unique only within each document. I.e., the
following is valid:
<doc>
<file>AAA</file>
<file>BBB</file>
</doc>
<doc>
<file>AAA</file>
</doc>

, while the following is not:
<doc>
<file>AAA</file>
<file>BBB</file>
<file>AAA</file> <!-- Matches previous file! -->
</doc>

--
Victor
Jul 20 '05 #1
3 1867


Victor Engmark wrote:
How do I define that the contents of an element should be unique only in
a sub-tree of the whole XML file?

In my case, I have several documents, each containing several files. The
file names have to be unique only within each document. I.e., the
following is valid:
<doc>
<file>AAA</file>
<file>BBB</file>
</doc>
<doc>
<file>AAA</file>
</doc>

, while the following is not:
<doc>
<file>AAA</file>
<file>BBB</file>
<file>AAA</file> <!-- Matches previous file! -->
</doc>


XML schema allows for uniqueness constraints, here is an example schema

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

<xs:element name="root">
<xs:complexType >
<xs:sequence>
<xs:element ref="doc" maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="doc">
<xs:complexType >
<xs:sequence>
<xs:element name="file" type="xs:string " maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueFil e">
<xs:selector xpath="file" />
<xs:field xpath="." />
</xs:unique>
</xs:element>

</xs:schema>

and an example document

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "test20040430Xs d.xml">
<doc>
<file>AAA</file>
<file>BBB</file>
</doc>
<doc>
<file>AAA</file>
<file>AAA</file>
</doc>
</root>

where the validation will flag an error for the second <file> element in
the second <doc> element.
--

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

Jul 20 '05 #2
Martin Honnen wrote:


Victor Engmark wrote:
How do I define that the contents of an element should be unique only
in a sub-tree of the whole XML file?

In my case, I have several documents, each containing several files.
The file names have to be unique only within each document. I.e., the
following is valid:
<doc>
<file>AAA</file>
<file>BBB</file>
</doc>
<doc>
<file>AAA</file>
</doc>

, while the following is not:
<doc>
<file>AAA</file>
<file>BBB</file>
<file>AAA</file> <!-- Matches previous file! -->
</doc>

XML schema allows for uniqueness constraints, here is an example schema

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

<xs:element name="root">
<xs:complexType >
<xs:sequence>
<xs:element ref="doc" maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="doc">
<xs:complexType >
<xs:sequence>
<xs:element name="file" type="xs:string " maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueFil e">
<xs:selector xpath="file" />
<xs:field xpath="." />
</xs:unique>
</xs:element>

</xs:schema>

and an example document

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "test20040430Xs d.xml">
<doc>
<file>AAA</file>
<file>BBB</file>
</doc>
<doc>
<file>AAA</file>
<file>AAA</file>
</doc>
</root>

where the validation will flag an error for the second <file> element in
the second <doc> element.


I tried this, but I have obviously overlooked something, because the
file http://vengmark.home.cern.ch/vengmar...ples/input.xml is
valid according to
http://vengmark.home.cern.ch/vengmar...amples/moi.xsd, even though
none of the ID elements are unique. Sorry the example is verbose...

--
Victor
Jul 20 '05 #3
Victor Engmark wrote:
I tried this, but I have obviously overlooked something, because the
file http://vengmark.home.cern.ch/vengmar...ples/input.xml is
valid according to
http://vengmark.home.cern.ch/vengmar...amples/moi.xsd, even though
none of the ID elements are unique. Sorry the example is verbose...


Disregard the previous message; I had got the scope of the unique
element wrong. Nevertheless, XML Spy v5 is unable to generate even
simplistic valid files of the new Schema document. Does anyone know a
tool with which I can generate "good" sample documents from Schemas? It
should give at least some control over the values entered into fields,
and shouldn't use several hundred MBs to generate a few MBs of XML...

--
Victor
Jul 20 '05 #4

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

Similar topics

2
3781
by: Dennis M. Marks | last post by:
I am never sure of when a semi-colon is required in javascript. Is there a definite rule? -- Dennis M. Marks -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
7
20961
by: jhomp ssens | last post by:
I would like to create a pulldown menu which is semi-transparent....that is, you can see the text and graphics behind it when it is pulled down. The effect I'm looking for can be seen at http://www.countrywide.com. Are there any good tutorials which can show me how to do this with CSS?
16
2847
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more semi-circular definitions and
2
3703
by: David Scemama | last post by:
Hi, I'm looking for a way to display semi graphic characters in a multi line text control or in a rich text control. I've tried with all the characters of the extended ASCII table (code page 437), they appear correctly except the semi graphic ones. Please help ... Thanks a lot
27
3184
by: StevePBurgess | last post by:
With a string of authors such as: Carson, David, Milne, Rebecca, Pakes, Francis J., Shalev, Karen, Shawyer, Andrea I would like to write a function to change every other comma into a semi colon (thereby defining where one name ends and the next begins). I could do it by writing a complex (and slow) procedure - but is there a quick way of doing it using regular expressions, for example?
2
2722
by: Trond Michelsen | last post by:
Hi. I have a transparent PNG-image that I would like to display on top of the rest of the web page. I've already got this part working. But, I'd like the background (as in "the part of the image that is transparent"), to be semi transparent instead. So, I've wrapped the image in a div-tag with the style "opacity: .70" instead. This gives me pretty much the semi transparency that I'm looking for, except that this makes the entire image...
2
2322
by: James Stroud | last post by:
Hello All, I am trying to create a semi-standalone with the vendor python on OS X 10.4 (python 2.3.5). I tried to include some packages with both --packages from the command and the 'packages' option in setup.py. While the packages were nicely included in the application bundle in both cases (at Contents/Resources/lib/python2.3/), they were not found by python when the program was launched, giving the error: "ImportError: No module...
0
1928
by: James Arnold | last post by:
I am trying to use a semi transparent PNG as the form background, allowing you to see through certain parts. The intention is similar to a skinnable form like launchy, with semi-transparent pixels (not just .MakeTransparent or Form.Opacity). Also similar to the Adobe splash screens which the feather and drop shadow. By overriding the OnPaint method and manually drawing a PNG onto the form background I can achieve this effect, but it does...
9
4127
by: JamesF1982 | last post by:
Hey everyone, My question is related to HTML, Javascript, CSS and ASP.NET but i think it belongs here! Upon an event i am trying to add a semi-transparent colour across the page so the background is obscurred but i also set a div with a known ID to exist above this. My current method has been to on the fly create a div which gets the screen height/width with javascript and then sets the image. However, my div is created but does not...
26
3056
by: machineghost | last post by:
First off, let me just say that as someone with no DBA training whatsoever, any help I can get with this issue will be very, very much appreciated. My company recently migrated our database from DB2 v7 to DB2 v9. We hired a consultant to help us, and things went pretty smoothly ... up until a few weeks after, when a co-worker tried to insert JavaScript in to our database. That's when we learned that v9, unlike v7, has a problem with...
0
9715
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
9595
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
10600
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
10352
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10097
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
9175
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
6867
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
5535
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
4313
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

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.