> I am trying to perform a SELECTNODES using a XPath statement from the
> original XML load, but I cannot seem to write this back out into a XML file.
> I realize the error is in sing the XmlNodeList statement, but I am a bit
> stumped.
> Public Function _
> GetService() As System.Xml.XmlDocument
It is not clear what you want to achieve. If the return type of the
function is XmlDocument then you can't return an XmlNodeList. You would
either need to manipulate the existing XmlDocument instance to remove
all nodes besides the ones in the node list (keeping the root element
perhaps or adding a new) or you would need to create a new XmlDocument
instance and then for instance use ImportNode to import the nodes from
the node list into the new document (after creating a root element first).

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
JD - 07 Apr 2006 17:52 GMT
Martin-
Thanks for the comments. Let me provide more detail on what I am trying to
accomplish:
I currently have a web service that when invoked will produce a XML file
that I have on the server....let's call it File A. I am producing the file
just by using the LOAD command from XMLDocument.
I want to write other functions in the web service that will return subsets
of File A. For example, take a look at the following XML:
<root>
<person>
<name>Jeff</name>
</person>
<place>
<location>Home</location>
</place>
</root>
Let's say that File A is the entire XML above, and I want to provide another
function that will just return everything from the PERSON tag.
I was trying to do this by using an XPath string under SelectNodes, but
maybe I am going about this the wrong way. What you said about writing the
NodeList back to an XML file makes perfect sense, but can I produce the XML
subset through the DOM just by performing a query?
I hope this provides more insight....Any further help is greatly
appreciated.
Thanks
JD
>> I am trying to perform a SELECTNODES using a XPath statement from the
>> original XML load, but I cannot seem to write this back out into a XML
[quoted text clipped - 11 lines]
> and then for instance use ImportNode to import the nodes from the node
> list into the new document (after creating a root element first).
Martin Honnen - 08 Apr 2006 12:51 GMT
> Let's say that File A is the entire XML above, and I want to provide another
> function that will just return everything from the PERSON tag.
[quoted text clipped - 3 lines]
> NodeList back to an XML file makes perfect sense, but can I produce the XML
> subset through the DOM just by performing a query?
Make the web method return XmlNode as the type and then use XPath and
SelectSingleNode to select whatever node you want to return e.g.
return aXmlDocument.SelectSingleNode("/root/person");
If you use SelectNodes then you have an XmlNodeList and that does
neither fit XmlDocument nor XmlNode. You don't have to write the
XmlNodeList back to a file on the file system but as said, if you want
the web method to return an XmlDocument instance then you need DOM code e.g.
XmlDocument responseXML = new XmlDocument();
responseXML.AppendChild(responseXML.CreateElement("new-root"));
while (xmlNodeListInstance.Count > 0) {
responseXML.DocumentElement.AppendChild(
responseXML.ImportNode(xmlNodeListInstance[0], true)
);
}
return responseXML;

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
JD - 09 Apr 2006 16:21 GMT
Martin-
Thanks for the tips. I decided to use the XMLNode method with the
SelectSingleNode(XPATH) return. Works like a charm....
I appreciate the help.
JD
>> Let's say that File A is the entire XML above, and I want to provide
>> another function that will just return everything from the PERSON tag.
[quoted text clipped - 20 lines]
> }
> return responseXML;