Reading XML attribute from a processing instruction line in C#

Tuesday, November 3, 2015

Platform: C#, .NET 4.5



I have the following line in a XML document



<?ish ishref="GUID-XXXXXXXXXXXXXXXXXXXX" version="1" lang="ae" srclng="en"?>



and want to read (and modify) the lang attribute. I have tried the following



newXMLDoc.Load(XMLfile);
instruction = newXMLDoc.SelectSingleNode("/processing-instruction('ish')") as XmlProcessingInstruction;



instruction returned a valid object with the innerText equal to "it's" line but I don't know how to access the attributes (tried various ways but all return null)



How do I Access the attributes of instruction (or is there another way of doing the access better) ?



PS



I have tried XPath like "/ish@lang" and instruction.Attributes but those just return NULL.



I would prefer a non LINQ solution



DS

0 comments:

Post a Comment