我正在努力从元素中获取价值,来自所有元素 但我只能得到第一个。 这是我使用的代码。
Dim xdoc As XDocument = root 'XDocument.Load("..\..\..\CountryState.xml") '
Dim Header As List(Of Bill) = ( _
From Head In (xdoc.Elements("FILE").Elements("BILL")) _
Select New Bill With { _
.countryName = Head.Element("CountryName").Value,
.Population = Head.Element("Population").Value,
.ASG_INVOICE_NO = (From el In Head...<ASG_INVOICE_NO> Select el).First(),
.BillDetail = (From Detail In
(Head.Element("BILL_SUMM").Element("BILL_SUMM_DETAILS").Element("ADDRESS_GROUP").Elements ("TARIFF")) _
Select New BillDetail With { _
.CIRCUIT_ID = (From D In Detail.Elements("UDFS") _
Where D.Element("UDF").Elements("COLUMN_NAME").Value = "CIRCUIT_ID" _
Select D.<UDF>.<UDF_VALUE>.<VALUE>.Value).FirstOrDefault() _
, .CUSTOM_DESC = (From D In Detail.Elements("UDFS") _
Where D.Element("UDF").Elements("COLUMN_NAME").Value = "CUSTOM_DESC" _
Select D.<UDF>.<UDF_VALUE>.<VALUE>.Value).FirstOrDefault() _
}).ToList()}).ToList()
结果是Header-&gt; "Panama 200000 100339"
第二行Detalle-&gt;的详细信息"8000307.SV"
缺少或无法从XML获取的值为"10 Mbps Curacao ECP"
它显示在"8000307.SV"
旁边的第二行,如Detalle-&gt; "8000307.SV" "10 Mbps Curacao ECP"
For Each H In Header
Console.WriteLine("Header-> " + H.countryName.Trim + " " + H.Population.Trim + " " + H.ASG_INVOICE_NO.Trim)
For Each D In co.BillDetail
Console.WriteLine("Detalle-> " + D.CIRCUIT_ID + " " + D.CUSTOM_DESC)
Next D
Next H
提前致谢...