我有一个cXML,我试图从...中读取一些值 我可以使用以下代码读取节点值。但我很难过 从同一文档中读取“payloadID”。有什么建议怎么办?
XmlDocument xmlRequest = new XmlDocument();
XmlNodeList name = xmlRequest.GetElementsByTagName("NetworkID");
string sSecret = name[0].InnerText;
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.023/cXML.dtd">
<cXML payloadID="1348609345562-715426217594539696@216.109.111.69"
timestamp="2012-09-11T11:55:53-07:00" version="1.2.023"
xml:lang="en-US">
<From>
<Credential domain="NetworkID">
<Identity>tnt</Identity>
</Credential>
</From>
<To>
<Credential domain="NetworkID1">
<Identity>abc</Identity>
</Credential>
</To>
</cXML>
答案 0 :(得分:1)
您应该能够获取根元素,然后使用其Attributes属性来读取该根元素的属性,例如:
XmlNode root = doc.SelectSingleNode("/cXML");
string attrVal = root.Attributes["payloadID"].Value;