Newbie question about validation

L

Leopold Schwinger

Hello!

I am just learning some basic concepts about xml in order
to write a small application.

Now my question:
I have an element, which content (text) must be the same,
as the content of another element. If you compare it to
relational databases, it is like a foreign key.

Is it possible to define this in a validating scheme?
If yes, how can I do it, and which "technology" would
you use (DTD, XML-Schemata or Relax NG)?

example (has nothing to do with the application):

<mydoc>
<!-- entire book collection -->
<book_collection>
<book>
<nr>001</nr>
<title>this is a nice book</title>
</book>
<book>
<nr>002</nr>
<title>one more book</title>
</book>
<book>
<nr>003</nr>
<title>my last book</title>
</book>
</book_collection>

<!-- my favorite books -->
<book_favorites>
<!-- the book_nr must appear under book_collection/book/nr> -->
<book_nr>001</book_nr>
<book_nr>003</book_nr>
</book_favorites>
</mdoc>

Thank you,
Leopold
 
M

Martin Honnen

Leopold Schwinger wrote:

I have an element, which content (text) must be the same,
as the content of another element. If you compare it to
relational databases, it is like a foreign key.

Is it possible to define this in a validating scheme?
If yes, how can I do it, and which "technology" would
you use (DTD, XML-Schemata or Relax NG)?

example (has nothing to do with the application):

<mydoc>
<!-- entire book collection -->
<book_collection>
<book>
<nr>001</nr>
<title>this is a nice book</title>
</book>
<book>
<nr>002</nr>
<title>one more book</title>
</book>
<book>
<nr>003</nr>
<title>my last book</title>
</book>
</book_collection>

<!-- my favorite books -->
<book_favorites>
<!-- the book_nr must appear under book_collection/book/nr> -->
<book_nr>001</book_nr>
<book_nr>003</book_nr>
</book_favorites>
</mdoc>

With a DTD you can't model that constrain as it only knows such
constraints for attributes (ID and IDREF), with a W3C XML schema you can
model that with key/keyref, see
http://www.w3.org/TR/xmlschema-0/#specifying Keys&theirRefs
Maybe someone else can tell you more about Relax NG.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top