By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

Read XML document from Web Service

P: n/a
Hello-

I am looking for the best way to run different Xpath expressions from a web
service, and return the appropriate XML data. The data source that the web
service queries is an XML file, that is not very large (less than 2 MB).

I can retrieve the entire XML file, but I would like to have separate
functions in the web service to pick out certain elements of the file and
basically filter the XML data. There are different methods for invoking
this action (XMLreader, XMLSelectNode, etc...). Can anyone provide some
guidance for the easiest method? Any examples would be most appreciated.

Thanks
Mar 16 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Here's something I wrote last week to work with XML messages
manually... I give it the xml and what I'm looking for. I expose this
to VB clients so they can access any property they want to in the web
service response message.

using System;
using System.Xml;

namespace XmlSupport
{
public static class XmlSearch
{
private static string FindLeaf(XmlNode node, string leaf) {
foreach (XmlNode child in node.ChildNodes) {
if (child.NodeType == XmlNodeType.Element) {
string returnValue = FindLeaf(child, leaf);
if (!String.IsNullOrEmpty(returnValue)) {
return returnValue;
}

}
else {
if (node.Name == leaf) {
if
(!String.IsNullOrEmpty(node.ChildNodes[0].Value)) {
return node.ChildNodes[0].Value;
}
else {
return String.Empty;
}
}
}
}

return String.Empty;
}

public static string SearchTree(string xml, string leaf) {
XmlDocument xmlDocument = new XmlDocument( );
xmlDocument.LoadXml(xml);

foreach (XmlNode node in xmlDocument.ChildNodes) {
string returnValue = FindLeaf(node, leaf);
if (!String.IsNullOrEmpty(returnValue)) {
return returnValue;
}
}

return String.Empty;
}
}
}

David Betz
WinFX Harmonics Blog
http://www.davidbetz.net/winfx/

Mar 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.