select dom text nodes

Discussion in 'XML' started by avsyam@gmail.com, Apr 13, 2007.

  1. Guest

    Hi,

    I want to select all the text nodes of an xml document using msxml
    dom. I tried using the selectNodes method with "//#text" argument. But
    it fails. Can anybody help please?

    Thank you.
     
    , Apr 13, 2007
    #1
    1. Advertising

  2. Guest

    On Apr 13, 11:22 am, wrote:
    > I want to select all the text nodes of an xml document
    > using msxml dom. I tried using the selectNodes method
    > with "//#text" argument.


    I don't believe there's a selectNodes() method in the W3C
    DOM specs. Assuming it accepts an XPath expression as an
    argument, what you need is '//text()'. #text is a nodeName,
    and is fairly meaningless in the context. Consider reading
    some sort of XPath tutorial, because invoking magic without
    understanding how it works is a recipe for disaster, as I
    can attest from painful personal experiences.

    --
    Pavel Lepin
     
    , Apr 13, 2007
    #2
    1. Advertising

  3. Guest

    Hey.. Thank you very much. That worked!!

    I m using MSXML and there is a selectNodes method.

    Yes, I agree that reading throughly before attempting a task is always
    the best way to work on something. Once in a while we all come across
    tasks where we dont have enough time to be thoroughly trained before
    attempting something.

    To be fair to me :), I did go thru the material in MSDN on XPath.
    Most of it is given in the context of XSLT. That partly obstructed my
    learning. Inspite of that, I didnt find any reference to selecting all
    text nodes.

    After you pointed out, I did check the w3schools tutorial where I
    found a similar point documented, thanks to you again. Btw, do you
    seriously think XPath is complex enough that we should master it
    before using it?
     
    , Apr 13, 2007
    #3
  4. In XPath, the pattern that matches text nodes is "text()".

    Note that XPath's idea of the document tree is not exactly the same as
    the DOM's model, so using XPath over a DOM involves a bit of translation
    and magic. The DOM Level 3 recommendation defines an API for using XPath
    with DOM that includes the necessary additional functions/behaviors to
    make that work, including hiding entity-reference boundaries and
    treating adjacent TEXT nodes as a single text() node.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Apr 13, 2007
    #4
  5. Guest

    Thank you.
     
    , Apr 13, 2007
    #5
  6. Guest

    On Apr 13, 3:04 pm, wrote:
    > Once in a while we all come across tasks where we dont
    > have enough time to be thoroughly trained before
    > attempting something.


    When something like that happens I go to the management and
    tell them something along the lines of 'You do realize this
    is just asking for trouble? You've been warned.' This often
    works. YMMV.

    > To be fair to me :), I did go thru the material in MSDN
    > on XPath. Most of it is given in the context of XSLT.
    > That partly obstructed my learning. Inspite of that, I
    > didnt find any reference to selecting all text nodes.


    If that is the case, the materials in question are of
    rather poor quality; however, I find that a bit hard to
    believe. Whatever you say about Microsoft, their references
    are usually up to snuff IME. It's more likely you weren't
    looking at them the right way.

    > After you pointed out, I did check the w3schools tutorial
    > where I found a similar point documented, thanks to you
    > again.


    W3schools has a somewhat mixed reputation. Some people
    swear by them, but they've been caught red-handed at
    posting almost blatantly ignorant advice in some of their
    tutorials.

    Joseph Kesselman usually refers people to IBM's collection
    of materials on XML, which is what I'm gonna do:

    http://www.ibm.com/xml/

    It's even easier for me, because unlike Joseph I'm not
    affiliated with IBM in any way (apart from having used an
    IBM G96 19" display several years ago, which was an almost
    orgastic experience).

    Note that the place is a treasure trove of useful
    information, which means it might seem a bit overwhelming.

    > Btw, do you seriously think XPath is complex enough that
    > we should master it before using it?


    I think you should at least attempt getting hang of
    *anything* you intend to use before trying to actually use
    it. This applies to anything up to and including
    chopsticks. Anyway, yes, I think XPath1 is complex enough
    if we start messing around with predicates, contexts and
    node identities, and I don't even mention XPath2. Note that
    while you seem to think XPath is easy you failed to solve a
    simple problem without asking for advice.

    --
    Pavel Lepin
     
    , Apr 13, 2007
    #6
  7. wrote:
    > seriously think XPath is complex enough that we should master it
    > before using it?


    Master? Maybe not.

    Spend time learning the basics? Yes, as with any tool. You can get away
    with just-in-time learning... but you do have to allow time for that
    learning. If management is in too much of a panic to let you do a good
    job, it may be time for them to hire a consultant to help you over the
    hump. Asking Usenet for advice is fine, but folks get irritated when it
    looks like you haven't done your homework first... and this really is a
    question that any semi-decent XPath tutorial should have answered.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Apr 13, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. asd
    Replies:
    3
    Views:
    458
    Arnaud Berger
    May 23, 2005
  2. Replies:
    2
    Views:
    1,243
  3. Michael Reiche
    Replies:
    3
    Views:
    10,964
    Michael Reiche
    Feb 5, 2004
  4. Xamle Eng

    Why treat text nodes as nodes?

    Xamle Eng, May 13, 2005, in forum: XML
    Replies:
    8
    Views:
    518
    Fredrik Lundh
    May 28, 2005
  5. Alan
    Replies:
    6
    Views:
    1,694
Loading...

Share This Page