Как прочитать инструкцию по обработке из XML-файла с помощью.NET 3.5

Как проверить, имеет ли XML-файл Инструкцию по обработке

Пример

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

 <Root>
    <Child/>
 </Root>

Я должен прочитать инструкцию по обработке

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

от XML-файла.

Помогите мне сделать это.

5
задан bluish 28 February 2012 в 15:20
поделиться

2 ответа

Как насчет:

XmlProcessingInstruction instruction = doc.SelectSingleNode("processing-instruction('xml-stylesheet')") as XmlProcessingInstruction;
16
ответ дан 18 December 2019 в 07:28
поделиться

Вы можете использовать свойство 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);
}

Parse Value или Data для получения соответствующих значений.

5
ответ дан 18 December 2019 в 07:28
поделиться
Другие вопросы по тегам:

Похожие вопросы: