You will need to associate a namespace prefix with the default namespace
that you are using in the
document(xmlns="http://www.govtalk.gov.uk/CM/envelope").
You do that by connecting an XmlNamespaceManager to the name table of your
XmlDocument,
and then specify a prefix that you want to use for that namespace URI.
I created an example, using "default" as the namespace prefix, seen below.
"default" should then be used in XPath evaluations as a prefix on any node
that uses that particular namespace(although in your case you use only one
namespace URI, there could be more than one).
Example:
XmlDocument doc = new XmlDocument();
doc.LoadXml(XMLstring);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("default", "http://www.govtalk.gov.uk/CM/envelope");
// NOtice we use "default" as prefix in the XPath.
XmlNode node = doc.DocumentElement.SelectSingleNode
(
"default:Body/default:StatusReport/default:StatusRecord/default:CorrelationID"
, nsmgr );
Console.WriteLine(node.OuterXml);
Console.Read();
HTH.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Adrian Parker" <ap******@nospam.com> wrote in message
news:Oy**************@tk2msftngp13.phx.gbl...
I have the following xml doc...
<?xml version="1.0"?>
<GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
<Body>
<StatusReport>
<StatusRecord>
<CorrelationID>E1308AB43036D8B8FCD2CBB1EE7FFA6B</CorrelationID>
</StatusRecord>
<StatusRecord>
<CorrelationID>CDDDD8EEBAFAE41A71FF24A3C36E7467</CorrelationID>
</StatusRecord>
</StatusReport>
</Body>
</GovTalkMessage>
I'm trying to get a list of the CorrelationID elements but can't seem to
get SelectNodes to find anything..
------------------------
XMLDoc.LoadXml(XMLstring)
nodeList =
XMLDoc.SelectNodes("/GovTalkMessage/Body/StatusReport/StatusRecord/CorrelationID")
For Each CorrelationID In nodeList
' do something with CorrelationID.Value
Next
------------------------
What am I doing wrong ?
Many Thanks
Adrian