Re: Using XPath Against A Node



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?

In the DOM an XmlNode always has an OwnerDocument property set to the document that created the node. A node cannot exist without its owning document as you can only create nodes with the factory methods of the XmlDocument instance. A node does not need to have a ParentNode property being non null however.

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. Thus if you do e.g.
Dim Xml_Doc as XmlDocument = New XmlDocument()
Dim SomeElement as XmlElement = Xml_Doc.CreateElement("whatever")
and pass that node around without inserting it into the document then the node in terms of XPath and SelectNodes/SelectSingleNode does not expose the document.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
.



Relevant Pages

  • Using XPath to copy nodes
    ... private Element getAnswers(Element root, String queID) throws ... XPath xpath = factory.newXPath; ... //Design the query to search through the XML Document ...
    (comp.lang.java.programmer)
  • Using XPath to copy nodes
    ... private Element getAnswers(Element root, String queID) throws ... XPath xpath = factory.newXPath; ... //Design the query to search through the XML Document ...
    (comp.lang.java.programmer)
  • 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: Please Help: SQLXML Bulk Load Error: Schema: relationship expected on Person
    ... <this is used when your xml document contains data for multiple tables in a ... Parent, child relationship> ... The following is the annotated schema: ... > No parent, ...
    (microsoft.public.sqlserver.xml)
  • Problem Joining Parent and Children
    ... I'm having problems joining the parent and children together from an ... parent rows. ... The XML Document is a little different than what I like to work with, ... exec sp_xml_preparedocument @hdoc output, @doc ...
    (microsoft.public.sqlserver.xml)