0

我有一个 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>
4

1 回答 1

1

您应该能够获取根元素,然后使用其 Attributes 属性来读取该根元素的属性,例如:

XmlNode root = doc.SelectSingleNode("/cXML");
string attrVal = root.Attributes["payloadID"].Value;
于 2012-09-25T22:23:26.663 回答