需要C#XML帮助 [英] C# XML Help Required
本文介绍了需要C#XML帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,其中有一个XML,我想读取特定节点的属性
例如,我有以下XML:
I have a string in which i have an XML,i want to read an attribute of a particular node
For eg I have following XML:
<?xml version="1.0" encoding="UTF-8"?>
<datatrace_services version="1.0" service="UPDATEUSERPROFILE">
<update_user_profile_response outcome="SUCCESS" type="UPDATE">
</xml>
如何在C#中读取update_user_profile_response结果属性?
How can i read update_user_profile_response outcome attribute in C#?
推荐答案
请参阅此 [^ ]线程.
首先使用LoadXml方法将Xml字符串读取到XmlDocument中,然后使用您的XmlDocument:
http://msdn.microsoft.com/en-us/library/system. xml.xmldocument.loadxml.aspx [ ^ ]
Read the Xml string into an XmlDocument using the LoadXml method first, then with your XmlDocument:
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx[^]
var myNode = myXmlDoc.GetElementsByTagName("update_user_profile_response")[0];
var outcome = myNode.Attributes["outcome"].Value;
这篇关于需要C#XML帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文