Tho*_*eld 5 c# xml .net-3.5 processing-instruction
如何检查Xml文件是否有处理指令
例
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
<Root>
<Child/>
</Root>
Run Code Online (Sandbox Code Playgroud)
我需要阅读处理指令
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
Run Code Online (Sandbox Code Playgroud)
来自XML文件.
请帮我这样做.
Gar*_*ett 16
怎么样:
XmlProcessingInstruction instruction = doc.SelectSingleNode("processing-instruction('xml-stylesheet')") as XmlProcessingInstruction;
Run Code Online (Sandbox Code Playgroud)
您可以使用类和类的FirstChild属性:XmlDocumentXmlProcessingInstruction
XmlDocument doc = new XmlDocument();
doc.Load("example.xml");
if (doc.FirstChild is XmlProcessingInstruction)
{
XmlProcessingInstruction processInfo = (XmlProcessingInstruction) doc.FirstChild;
Console.WriteLine(processInfo.Data);
Console.WriteLine(processInfo.Name);
Console.WriteLine(processInfo.Target);
Console.WriteLine(processInfo.Value);
}
Run Code Online (Sandbox Code Playgroud)
解析Value或Data属性以获得适当的值.