Re: tdom xpath search

From: Rolf Ade (pointsman_at_gmx.net)
Date: 03/17/05


Date: Thu, 17 Mar 2005 13:00:25 +0000 (UTC)

In article <d1bcr4$mt1$1@news.u-strasbg.fr>,
Jeannot <jean.muller@igbmc.u-strasbg.fr> wrote:
>I am actually working on XML files and I use tdom as a handler of xml. I
> have a question concerning xpath expression. I need to search all
>nodes (sequence) which child (seq-name) contains a certain string:
>
>So I try this "/MSA/alignment/sequence\[string(seq-name)='toto'\]" which
>help me to find the node that exactly match toto and now I need to find
>'toto_*' and so I try this
>:"/MSA/alignment/sequence\[string(seq-name)='toto_*'\]" and it does not
>work like this !!!

Sure. This query simply does not, what you intend; XPath 1.0 doesn't
know string matching wild-cards. For your case, you could use the
XPath function starts-with():

/MSA/alignment/sequence[starts-with(seq-name,'toto_')]

A few notes:
You didn't need 'string(seq-name)'. If the the context of the
expression requires a string, the selected node-set will automatically
be converted to a string value, exactly as string() does it.

This expression will only do what you (probably) want, if there is
always only maximum one seq-name child below sequence or if it's
always the first seq-name child below sequence, which is relevant. If
you have sequence nodes with more than one seq-name childs and you
want to select all sequence with at least one seq-name with a text
content, which starts with 'toto_' you'll need another query like:
/MSA/alignment/sequence[seq-name[starts-with(.,'toto_')]]

Your question is not tcl or tdom related, but an XPath language
question. Asking such questions at a related place, as the xslt
mailing list (http://www.mulberrytech.com/xsl/xsl-list/) may get you
faster/better answers than asking this at c.l.t.

rolf



Relevant Pages

  • Re: tdom xpath search
    ... >>I am actually working on XML files and I use tdom as a handler of xml. ... > know string matching wild-cards. ... > always the first seq-name child below sequence, ...
    (comp.lang.tcl)
  • Merry Christmas!
    ... dictionaries and every variant possibility has a separate "word" entry. ... The byte string of the "word", whose length is specified by a four ... match is found for a source byte sequence in the dictionary. ...
    (rec.arts.sf.written)
  • Merry Christmas! Linux RULES! New applications to develop!
    ... dictionaries and every variant possibility has a separate "word" ... Each entry in the dictionary contains: ... The byte string of the "word", whose length is specified by a four ... addresses whose entry is selected by the first byte of the sequence. ...
    (comp.os.linux.misc)
  • Re: user defined function that converts string to float
    ... > I need user defined function that converts string to float in c. ... initial, possibly empty, sequence of white-space characters (as ... point character, then an optional exponent part as defined in ... then a nonempty sequence of hexadecimal digits ...
    (comp.lang.c)
  • Re: Coin tossing guessing strategy...
    ... You need a precise string in exactly one order, ... with respect to sequences of n flips, is to note that if some sequence ... In fact, assuming a fair coin, all 10 coin sequences are equally ... heads and tails. ...
    (sci.math)