【问题标题】:XML Data parsing issueXML 数据解析问题
【发布时间】:2016-06-22 15:34:45
【问题描述】:

您好,在我的项目中,我需要加载 XML 文件,但显示根级别的数据无效。第 1 行,位置 1 错误。

我的代码如下

        feedxml.Load(HttpContext.Current.Server.MapPath("feed.xml"));
        XmlElement root = (XmlElement)feedxml.DocumentElement;
        XmlElement xmlele = ((XmlElement)root.SelectNodes("categoryList")[0]);

我的xml文件如下。

【问题讨论】:

    标签: xml


    【解决方案1】:

    使用XElement,使用简单
    using System.Xml.Linq
    XElement file=XElement.Load(HttpContext.Current.Server.MapPath("feed.xml"));
    foreach(var category in file.Elements("categoryList"))
    {
    //you can get value and attribuets's values of category tag // you can write file.Descendants("categoryList") too
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多