Re: Using XPath Against A Node



If there is some reason you don't want a method to access the document
from a node, it is possible to create a new xml document with only that
node and its descendants and pass it to a method. If the method
modifies the node you will need to do some work to replace the original
node with the modified node.

I don't know of any way to "protect" ancestor nodes within the DOM.

Derek Hart wrote:
So if I pass a node to a function, can I treat the top-most element as the
top parent? That is my question. Or is the entire xml document sent with
it. I do not want it to be possible to look at the whole document in the
function. I just want to pass in a specific node. Is it possible?

Derek


"FishingScout" <fishingscout@xxxxxxxxxxx> wrote in message
news:1165383052.131851.94120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Derek,

I am not sure what you meant by: "and I could assume that the top part
of that node was the new parent."

Using "/" will search the document root node immediate descendants.
Using "./" will search the context node immediate descendants.
Using "// will search anywhere in the entire document.
Using ".//" will search anywhere in the context node descendants.
Similarly, you could use "descendant::".

If you know the absolute path of the data you are looking for, you can
simply skip the "//" or the "/". For example, if "Price" were an
attribute of "Model", which is an immediate descendant of Vehicles, you
could query for the price of a model using "Model/@Price". If you are
a high paid developer you could search for a specific model using
"Model[.='Cadillac']/@Price". You don't need to use ".//Model/@Price"
or "descendant::Model/@Price".

I don't know if this was helpful but .... I don't drive a Cadillac.


Derek Hart wrote:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I
run xpath statements against the xml file to grab data from it, so I use,
as
an example, //Vehicles/Vehicles/@make to get the make of the car. But
then
I pass a specific node from xmlDoc into another function, not the whole
xmlDoc, just a node from it. And if I run an xpath against it, I have to
use .// (has a period at the beginning) so it does not grab info from the
parent. So I would have to use .//Vehicles/Vehicles/@make so it
references
the current node. I would think that if I passed a node to a vb.net
function, I could simply use an xpath statement that would work off the
passed in node, and I could assume that the top part of that node was the
new parent. Is there a way to pass a node like this?

Derek


.



Relevant Pages

  • Re: Using XPath Against A Node
    ... of that node was the new parent." ... Using "/" will search the document root node immediate descendants. ... run xpath statements against the xml file to grab data from it, so I use, as ... I pass a specific node from xmlDoc into another function, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Using XPath Against A Node
    ... Any sample code on breaking the node off the original xml document into its ... Using "/" will search the document root node immediate descendants. ... run xpath statements against the xml file to grab data from it, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Using XPath Against A Node
    ... of that node was the new parent." ... Using "/" will search the document root node immediate descendants. ... run xpath statements against the xml file to grab data from it, so I use, ... I pass a specific node from xmlDoc into another function, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Problem with AppendChild
    ... The limitations are not so short as that, does your XML document have a DTD that says otherwise? ... It's not clear if CLIENT-SERVER-INTERFACE is the "parent" you speak of or is the node you are adding to something unmentioned. ... public class DomExample { ... DocumentBuilder builder = null; ...
    (comp.lang.java.help)
  • Re: Using XPath Against A Node
    ... top parent? ... Or is the entire xml document sent with it. ... In terms of the XPath implementation with SelectSingleNode and SelectNodes if the node is not inserted in the owning document then it looks like the XPath / evaluates to the node itself. ...
    (microsoft.public.dotnet.languages.vb)

Loading