如何读取xml文件子节点并将其显示到c#中的datagridview [英] how to read xml file child node and display it to datagridview in c#
问题描述
我正在尝试读取xml文件并显示到datagridview。虽然我能够显示标题项只有子节点丢失 i'm trying to read an xml file and display to datagridview. while doing i'm able to display header items only child nodes are missing 这篇关于如何读取xml文件子节点并将其显示到c#中的datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
xml文件
< pre lang =xml> - < EclipseHeader OpportunityID = < span class =code-attribute> CurrencyCode = AD PriceTerm = DF 国家/地区 = AU OrigApplication = SBW SupplyChain = BTCO ConfigID = 10001 SKU = 待定 NetPrice = 0 ConfigName = StoreEasy 1640 - 磁带选项 - 25-2-2015 / HP StoreEasy 1640 16TB SAS存储#3 >
- < EclipseLineItems >
< EclipseLineItem NetPrice = 17630 级别 = 1 < span class =code-attribute> IntegrationGroupCode = 20101 描述 = HP StoreEasy 1640 16TB SAS存储 数量 = 1 ProductNumber = E7W82A TagText = NA / >
< EclipseLineItem NetPrice = 0 < span class =code-attribute> 级别 = 1 IntegrationGroupCode = 20101 描述 = HP 4Y 4小时24x7 Proactive Care SVC 数量 = 1 ProductNumber = H1K92A4 TagText = NA / >
< EclipseLineItem NetPrice = 3989 级别 = 2 IntegrationGroupCode = 20101 描述 = HP StoreEasy 1440/1640支持 数量 = 1 ProductNumber = H1K92A4 SPV TagText = NA / >
< EclipseLineItem NetPrice = 0 < span class =code-attribute> 级别 = 1 IntegrationGroupCode = 20101 描述 = HP安装服务 数量 = 1 ProductNumber = HA113A1 TagText = NA / >
< EclipseLineItem NetPrice = 2625 等级 = 2 IntegrationGroupCode = 20101 描述 =
< EclipseLineItem NetPrice = 439 < span class =code-attribute>级别 = 1 IntegrationGroupCode = 20101 描述 = HP H221 PCIe 3.0 SAS HBA 数量 = 1 < span class =code-attribute> ProductNumber = 729552-B21 TagText = NA / >
< / EclipseLineItems >
< / EclipseHeader >
我的代码
OpenFileDialog openfiledialog2 = new OpenFileDialog();
if(openfiledialog2.ShowDialog()== System.Windows.Forms.DialogResult.OK)
{
this.txtXML.Text = openfiledialog2.FileName;
}
DataSet ds = new DataSet();
string xmlfile = txtXML。文字;
ds.ReadXml(xmlfile);
dgvExcelRResult.DataSource = ds.Tables [0]; 试试这里:
http://www.aspdotnet-suresh.com/2012/05/aspnet-read-xml-node-values-and-bind.html [ ^ ]
xml file
-<EclipseHeader OpportunityID="" CurrencyCode="AD" PriceTerm="DF" Country="AU" OrigApplication="SBW" SupplyChain="BTCO" ConfigID="10001" SKU="TBD" NetPrice="0" ConfigName="StoreEasy 1640 - Tape Options - 25-2-2015/HP StoreEasy 1640 16TB SAS Storage #3">
-<EclipseLineItems>
<EclipseLineItem NetPrice="17630" Level="1" IntegrationGroupCode="20101" Description="HP StoreEasy 1640 16TB SAS Storage" Quantity="1" ProductNumber="E7W82A" TagText="NA"/>
<EclipseLineItem NetPrice="0" Level="1" IntegrationGroupCode="20101" Description="HP 4Y 4 hr 24x7 Proactive Care SVC" Quantity="1" ProductNumber="H1K92A4" TagText="NA"/>
<EclipseLineItem NetPrice="3989" Level="2" IntegrationGroupCode="20101" Description="HP StoreEasy 1440/1640 Support" Quantity="1" ProductNumber="H1K92A4 SPV" TagText="NA"/>
<EclipseLineItem NetPrice="0" Level="1" IntegrationGroupCode="20101" Description="HP Installation Service" Quantity="1" ProductNumber="HA113A1" TagText="NA"/>
<EclipseLineItem NetPrice="2625" Level="2" IntegrationGroupCode="20101" Description="HP StoreEasy 1000 3000 Install SVC" Quantity="1" ProductNumber="HA113A1 5AM" TagText="NA"/>
<EclipseLineItem NetPrice="439" Level="1" IntegrationGroupCode="20101" Description="HP H221 PCIe 3.0 SAS HBA" Quantity="1" ProductNumber="729552-B21" TagText="NA"/>
</EclipseLineItems>
</EclipseHeader>
my code
OpenFileDialog openfiledialog2 = new OpenFileDialog();
if (openfiledialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtXML.Text = openfiledialog2.FileName;
}
DataSet ds = new DataSet();
string xmlfile = txtXML.Text;
ds.ReadXml(xmlfile);
dgvExcelRResult.DataSource = ds.Tables[0];try here:
http://www.aspdotnet-suresh.com/2012/05/aspnet-read-xml-node-values-and-bind.html[^]