7

Xmlファイルに処理命令があるかどうかを確認する方法

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

 <Root>
    <Child/>
 </Root>

処理命令を読む必要があります

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

XML ファイルから。

これを行うのを手伝ってください。

4

3 に答える 3

18

どうですか:

XmlProcessingInstruction instruction = doc.SelectSingleNode("processing-instruction('xml-stylesheet')") as XmlProcessingInstruction;
于 2010-06-23T18:38:58.887 に答える
5

クラスとクラス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プロパティを解析して、適切な値を取得します。

于 2010-06-23T09:40:59.703 に答える
0

コンパイラにもっと多くの作業を任せてみませんか:

XmlDocument Doc = new XmlDocument();
Doc.Load(openFileDialog1.FileName);

XmlProcessingInstruction StyleReference = 
    Doc.OfType<XmlProcessingInstruction>().Where(x => x.Name == "xml-stylesheet").FirstOrDefault();
于 2016-09-23T19:13:35.183 に答える