Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / April 2006

Tip: Looking for answers? Try searching our database.

load Xpath document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JD - 07 Apr 2006 17:13 GMT
Hello-

I am a beginner to .NET XML, and I currently have a web service that returns
a full XML document.  I want to use an XPath statement to return a portion
of the same XML file in a new function.

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.

Any ideas?

Here is my code:

Public Function _
GetService() As System.Xml.XmlDocument

Dim myXML As New XmlDocument()

Dim specs As String

specs = "/Root/Bind/Application[1]"

myXML.Load("App_Data/data.xml")

Dim myXmlNodeList As XmlNodeList = myXML.SelectNodes(specs)

myXML.Load(myXmlNodeList)

GetService = myXML

End Function
Martin Honnen - 07 Apr 2006 17:22 GMT
> 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;

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.