Using XmlDocument to Retrieve values in c#

后端 未结 2 588
灰色年华
灰色年华 2021-01-13 18:14

I am using XmlDocument() for parsing a file like **.opf ** for my application of EpubReader.



        
2条回答
  •  情歌与酒
    2021-01-13 18:54

    Following code loads and parses content.opf file without any error.

    To iterate and compare above xml you may use following code:

    try
    {
        XmlDocument xDoc = new XmlDocument();
        xDoc.Load("content.opf");
    
        XmlNodeList items = xDoc.GetElementsByTagName("item");
        foreach (XmlNode xItem in items)
        {
            string id = xItem.Attributes["id"].Value;
            string href= xItem.Attributes["href"].Value;
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
    }
    

提交回复
热议问题