[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [xml-dev] Unique values in XML documents
- From: "Ernest G. Allen" <firstname.lastname@example.org>
- To: Matt Loryman <email@example.com>, firstname.lastname@example.org
- Date: Mon, 24 Sep 2001 11:49:59 -0700
Neither DTD nor XML Schema let you check or enforce that all
character data of a certain element type is unique across
multiple documents. It must be done by an application.
To ensure that the values are unique when they are created you
can follow some convention, such as concatenating the name of
the file and a sequential counter into the unique values.
Depending on the nature of the application, time stamps might be
useful. Fancier applications might use a "ticket server" that
issues sequential (or otherwise unique) strings or numbers.
To check the uniquness of the values of attributes of type ID
across multiple documents I've often created a new DTD which
includes all of the old DTD plus a new root element, say
big_collection, which has as its content model (old_root+).
Concatenate all of the existing documents into one big document,
with the new <big_collection>...</big_collection> "wrapper" and
If the values to be checked are character data you can copy them
into a new ID-type attribute as you concatenate them into the
single big file and then use a validating parser. Another easy
approach to check the character content of all of your "id"
elements would be to create ESIS or PYX output for each XML file
and then write a short program to process the ESIS (or PYX),
looking for duplicates.
/s/ Ernest G. Allen
At 3:12 PM -0700 2001-09-24, Christian Nentwich wrote:
>> At 9:04 AM -0700 2001-09-24, Matt Loryman wrote:
>> I have a series of XML documents. I want to ensure that when any of these
>> contains the following element:
>> That the value supplied is unique across all <id> elements contained in all
>> the documents.
>You can do this quite easily in xlinkit (see http://www.xlinkit.com) as
><forall var="x" in="//id">
> <forall var="y" in="//id">
> <equals op1="$x/text()" op2="$y/text()"/>
> <same op1="$x" op2="$y"/>
>Depending on how complex your constraints get, this may/may not be
>inconvenient for you.