开发者

Display RAW XML to a string or Label and find out particular Tag from that XML

开发者 https://www.devze.com 2023-02-03 14:30 出处:网络
I will g开发者_如何学Cet this in a Raw format and i am writing this using Response.write(\"Some.xml\");

Display RAW XML to a string or Label and find out particular Tag from that XML

I will g开发者_如何学Cet this in a Raw format and i am writing this using

      Response.write("Some.xml");

I need to find out MerchantOrderNumber from this raw data how to obtain this


Your best bet would be to load the XML into an XML parser e.g. XDocument:

XDocument xdoc = XDocument.Parse("SomeXml");
string merchantOrderNumber = xdoc.Descendants("MerchantOrderNumber").First().Value;                

Edit

If you are using .NET 2.0 then you can use XmlDocument e.g.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXML("SomeXml");
string merchantOrderNumber = xmlDoc.GetElementsByTagName("MerchantOrderNumber")[0].InnerText;


You could do this using XPath, something like this:

XPathDocument doc = new XPathDocument("Some.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile("/xml/Order/MerchantOrderNumber");
XPathNodeIterator nodes = nav.Select(expr);
string merchNum = string.Empty;
if(nodes.MoveNext())
{
   merchNum = nodes.Current.Value;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号