Thorin Oakenshield Thorin Oakenshield - 2 months ago 20
C# Question

How to read processing instruction from an XML file using .NET 3.5

How to check whether an Xml file have processing Instruction

Example

<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>

<Root>
<Child/>
</Root>


I need to read the processing instruction

<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>


from the XML file.

Please help me to do this.

Answer

How about:

XmlProcessingInstruction instruction = doc.SelectSingleNode("processing-instruction('xml-stylesheet')") as XmlProcessingInstruction;
Comments