讀取xml文件

知道xml路徑spa

讀取xmlcode

先用filestreamxml

 using (FileStream OpenFileStream =
                    new FileStream(ConfigurationXmlPath, FileMode.Open))

將獲得的filestream轉換爲stringblog

 string data = StreamManager.Stream2String(OpenFileStream);

實例化一個xmldocumentelement

將上一步獲得的字符串加載成xml文件字符串

 XmlDocument doc = new XmlDocument();
                    doc.LoadXml(data);

而後就能夠對這個doc裏面的節點進行操做了string

   doc.LoadXml(data);
                    XmlNode DocElementNode = doc.SelectSingleNode("DocumentElement");

這樣就能夠取到特定節點下面的內容啦io

也能夠循環節點下面的子節點class

foreach (XmlNode AppNode in ApplicationsNode.ChildNodes)
                    {}

同時能夠獲取節點內容test

   XmlElement element = (XmlElement)AppNode;
string test=element.GetAttribute("JobPath");
相關文章
相關標籤/搜索