【问题标题】:Query XML file in asp.net?在 asp.net 中查询 XML 文件?
【发布时间】:2014-03-07 09:56:46
【问题描述】:

我使用简单的 sql 表和程序来绑定我的 DropDownlist,但似乎需要一些时间来加载列表中的项目。所以现在我正在尝试将我的 DropDownList 与包含数据的 XML 文件文件绑定我想将我的 DropDownList 与..绑定。

我的代码

 XElement main = XElement.Load(filePath);
        IEnumerable<XElement> searched =
            from c in main.Elements("GLCODE")
            where (string)c.Element("GLCODEITEM").Attribute("PostingGL") == "200142"
            select c;
        DropDownList1.DataSource = searched;
        DropDownList1.DataTextField = "GL";
        DropDownList1.DataValueField = "PostingGL";
        DropDownList1.DataBind();

我的 XML

<GLCODE>
  <GLCODEITEM>
    <PostingGL>200085</PostingGL>
    <GL>200085 - Bank charges</GL>
  </GLCODEITEM>
  <GLCODEITEM>
    <PostingGL>200089</PostingGL>
    <GL>200089 - ROC FEES</GL>
  </GLCODEITEM>
  <GLCODEITEM>
    <PostingGL>200098</PostingGL>
    <GL>200098 - STAMP DUTY CHARGES</GL>
  </GLCODEITEM>      
  <GLCODEITEM>
    <PostingGL>200130</PostingGL>
    <GL>200130 - Consumables - Backup Tapes</GL>
  </GLCODEITEM>
  <GLCODEITEM>
    <PostingGL>200130</PostingGL>
    <GL>200130 - Consumables - Miscellaneous</GL>
  </GLCODEITEM>
  <GLCODEITEM>
    <PostingGL>200133</PostingGL>
    <GL>200133 - ELECTRICITY EXPENSES</GL>
  </GLCODEITEM>      
  <GLCODEITEM>
    <PostingGL>200140</PostingGL>
    <GL>200140 - PROFESSION TAX - COMPANY</GL>
  </GLCODEITEM>
  <GLCODEITEM>
    <PostingGL>200142</PostingGL>
    <GL>200142 - REPAIRS AND MAINTENANC</GL>
  </GLCODEITEM>
</GLCODE>

问题是我的 DropDownList 中没有任何价值。 有人可以教我一些简单的方法来查询 XML 之类的吗 SELECT name,phoneno FROM Table WHERE Country="abc"

【问题讨论】:

    标签: c# asp.net xml


    【解决方案1】:
    XElement xelement = XElement.Load("..\\..\\Employees.xml");
    var addresses = from address in xelement.Elements("GLCODE")
                    where (string)address.Element("GLCODEITEM").Element("PostingGL") == "20014"
                   select address;
    foreach (XElement xEle in address)
    {
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 2012-01-20
      相关资源
      最近更新 更多