Tho*_*eld 5 c# xml .net-3.5 processing-instruction
如何检查Xml文件是否有处理指令
例
 <?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
 <Root>
    <Child/>
 </Root>
我需要阅读处理指令
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
来自XML文件.
请帮我这样做.
Gar*_*ett 16
怎么样:
XmlProcessingInstruction instruction = doc.SelectSingleNode("processing-instruction('xml-stylesheet')") as XmlProcessingInstruction;
您可以使用类和类的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);
}
解析Value或Data属性以获得适当的值.
| 归档时间: | 
 | 
| 查看次数: | 5901 次 | 
| 最近记录: |