Xmlファイルに処理命令があるかどうかを確認する方法
例
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
<Root>
<Child/>
</Root>
処理命令を読む必要があります
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
XML ファイルから。
これを行うのを手伝ってください。
Xmlファイルに処理命令があるかどうかを確認する方法
例
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
<Root>
<Child/>
</Root>
処理命令を読む必要があります
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
XML ファイルから。
これを行うのを手伝ってください。
どうですか:
XmlProcessingInstruction instruction = doc.SelectSingleNode("processing-instruction('xml-stylesheet')") as XmlProcessingInstruction;
クラスとクラスFirstChild
のプロパティを使用できます:XmlDocument
XmlProcessingInstruction
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
プロパティを解析して、適切な値を取得します。
コンパイラにもっと多くの作業を任せてみませんか:
XmlDocument Doc = new XmlDocument();
Doc.Load(openFileDialog1.FileName);
XmlProcessingInstruction StyleReference =
Doc.OfType<XmlProcessingInstruction>().Where(x => x.Name == "xml-stylesheet").FirstOrDefault();