.NET 3.5を使用してXMLファイルから処理命令を読み取る方法
-
29-09-2019 - |
質問
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();
所属していません StackOverflow