Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Question about tag and value

Reply
Thread Tools

Question about tag and value

 
 
mittra@juno.com
Guest
Posts: n/a
 
      11-05-2007
Hello All,

I am a newbie to XML. I have the following question: how do I express
something in XML when the subsequent tag structures depends on the
value of a preceeding tag?

For example, when TAG2 has a value of 1, then TAG3 exists.

<TAG1>
<TAG2>1</TAG2>
<TAG3>some_value</TAG3>
</TAG1>

But when TAG2 has a value of 2, then TAG4 exists.

<TAG1>
<TAG2>2</TAG2>
<TAG4>some_value2</TAG4>
</TAG1>

Can the above two be combined into a single structure for TAG1?

Thanks for your insight.

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      11-06-2007
wrote:
> I am a newbie to XML. I have the following question: how do I express
> something in XML when the subsequent tag structures depends on the
> value of a preceeding tag?


Neither DTDs nor XML Schema allow you to use the value of an element or
attribute to constrain the presence or another -- with the exception of
the xsi:type attribute; see a good XML Schema tutorial (or a great deal
of recent discussion in this very newsgroup) for details of how to use
that sub-typing feature.

You *can* structure things so the presence or absence of your <TAG2>
element gates whether TAG3 or TAG4 was expected after it, by writing the
appropriate content models in your DTD or Schema.

Or you can enforce the cross-constraint in your application rather than
expecting the document formalism to do it all. Remember, neither DTDs
nor schemas are intended to capture all the semantics of a document, and
some checking will always have to be done by the application --
vaidation only provides an initial layer and some "machine-readable
documentation" of what's expected.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      11-06-2007
Joseph Kesselman wrote:
> vaidation only provides an initial layer and some "machine-readable
> documentation" of what's expected.


Putting it another way -- Validity, if you're enforcing it, documents
things that are Necessary for a correct document, but may not enumerate
everything that is Sufficient for it to be correct.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
mittra@juno.com
Guest
Posts: n/a
 
      11-06-2007
On Nov 5, 4:29 pm, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
> mit...@juno.com wrote:
> > I am a newbie to XML. I have the following question: how do I express
> > something in XML when the subsequent tag structures depends on the
> > value of a preceeding tag?

>
> Neither DTDs nor XML Schema allow you to use the value of an element or
> attribute to constrain the presence or another -- with the exception of
> the xsi:type attribute; see a good XML Schema tutorial (or a great deal
> of recent discussion in this very newsgroup) for details of how to use
> that sub-typing feature.
>
> You *can* structure things so the presence or absence of your <TAG2>
> element gates whether TAG3 or TAG4 was expected after it, by writing the
> appropriate content models in your DTD or Schema.
>
> Or you can enforce the cross-constraint in your application rather than
> expecting the document formalism to do it all. Remember, neither DTDs
> nor schemas are intended to capture all the semantics of a document, and
> some checking will always have to be done by the application --
> vaidation only provides an initial layer and some "machine-readable
> documentation" of what's expected.
>
> --
> Joe Kesselman / Beware the fury of a patient man. -- John Dryden


Thanks. I will look into XML Schema tutorial.

However, from your respnse it seems I might not have communicated the
objective behind doing this. While I can enforce the check of the
subsequent tag structure (TAG3 or TAG4) in the application domain, the
primary objective is to define *one* XML structure that (based on
TAG2) defines the *entire* structure. This will be akin to saying, in
this example,

if (TAG2 value is 1) then
<TAG3>some_value</TAG3>
else
<TAG4>some_value2</TAG4>

Perhaps, XML Schema does it?

 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      11-06-2007
wrote:
> if (TAG2 value is 1) then
> <TAG3>some_value</TAG3>
> else
> <TAG4>some_value2</TAG4>


Neither XML Schema nor DTDs can express that constraint, except by using
xsi:type. Some of the less-widely-supported schema languages can (I
think both RelaxNG and Schematron can do this) -- but then you have the
problem of whether your users will accept those solutions.

Again: The simplest answer is to fix it in documentation and in
application code.


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Philippe Poulard
Guest
Posts: n/a
 
      11-06-2007
hi,

a écrit :
>
> if (TAG2 value is 1) then
> <TAG3>some_value</TAG3>
> else
> <TAG4>some_value2</TAG4>
>
> Perhaps, XML Schema does it?
>


this is exactly the way the Active Schema Language works : you can
define dynamically the content model that suits your needs, potentially
with the help of if-then-else statements

although ASL is experimental, it is implemented and works fine : you can
use it for your own needs if you don't have to share your own schemas
with third-party users ; ASL will allow you to express much more complex
constraints than legacy schema technologies can (DTD, W3C XML Schema,
RelaxNG, Schematron)

the implementation :
http://reflex.gforge.inria.fr/
the specification :
http://ns.inria.fr/active-tags/activ...ve-schema.html
some tutorials :
http://reflex.gforge.inria.fr/tutorial-schemas.html

if you are new to XML, you'll have to understand namespaces in XML and
learn XPath before (which are widely used in XML technologies)

some courses :
http://disc.inria.fr/perso/philippe....namespaces.pdf
http://disc.inria.fr/perso/philippe....-xml-xpath.pdf
....if you are new to french, you'll have to learn french before

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find <tag> to </tag> HTML strings and 'save' them? mark@agtechnical.co.uk Python 7 03-26-2007 04:11 PM
Parsing an XML file and adding another tag, if the tag is not available / the value is null P Perl Misc 7 01-12-2007 03:28 AM
only a simple xml reader <tag:id>value</tag:id> martijn@gamecreators.nl Python 4 02-11-2006 06:44 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
How to tranform an XML tag value to an atrribute value su XML 2 01-16-2006 12:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57