How to read processing instruction from an XML file using .NET 3.5

前端 未结 3 1597

How to check whether an Xml file have processing Instruction

Example

 

 
          


        
3条回答
  •  独厮守ぢ
    2021-01-12 22:46

    You can use FirstChild property of XmlDocument class and XmlProcessingInstruction class:

    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 or Data properties to get appropriate values.

提交回复
热议问题