Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   select dom text nodes (http://www.velocityreviews.com/forums/t500204-select-dom-text-nodes.html)

avsyam@gmail.com 04-13-2007 08:22 AM

select dom text nodes
 
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.


p.lepin@ctncorp.com 04-13-2007 11:23 AM

Re: select dom text nodes
 
On Apr 13, 11:22 am, avs...@gmail.com 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


avsyam@gmail.com 04-13-2007 12:04 PM

Re: select dom text nodes
 
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?


Joe Kesselman 04-13-2007 12:20 PM

Re: select dom text nodes
 
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

avsyam@gmail.com 04-13-2007 12:42 PM

Re: select dom text nodes
 
Thank you.


p.lepin@ctncorp.com 04-13-2007 01:44 PM

Re: select dom text nodes
 
On Apr 13, 3:04 pm, avs...@gmail.com 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


Joseph Kesselman 04-13-2007 02:46 PM

Re: select dom text nodes
 
avsyam@gmail.com 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


All times are GMT. The time now is 09:44 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.