Reading values from xml document

297 Views Asked by At

I have an cXML that I am trying to read some values from.... I can read the node values using following code. But I am having hard time reading the "payloadID" from the same document. Any suggestions how to go about it?

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="[email protected]"
        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>
1

There are 1 best solutions below

0
On BEST ANSWER

You should be able to get the root element and then use its Attributes property to read the attributes of that root element, e.g.:

XmlNode root = doc.SelectSingleNode("/cXML");
string attrVal = root.Attributes["payloadID"].Value;