<Documents>
<Sales>
<Total>81678.600000</Total>
<Invoice>
<InvoiceNum>153</InvoiceNum>
<Date>2013-03-01</Date>
<Customer>2589</Customer>
<Line>
<ProductId>AT.02-2584</ProductId>
<Description>Product 1</Description>
<Quantity>1.000</Quantity>
<UnitPrice>265.140000</UnitPrice>
</Line>
</Invoice>
<Invoice>
<InvoiceNum>154</InvoiceNum>
<Date>2013-03-01</Date>
<Customer>2589</Customer>
<Line>
<ProductId>AT.02-2584</ProductId>
<Description>Product 1</Description>
<Quantity>1.000</Quantity>
<UnitPrice>265.140000</UnitPrice>
</Line>
<Line>
<ProductId>AT.02-2599</ProductId>
<Description>Product 2</Description>
<Quantity>1.000</Quantity>
<UnitPrice>85.100000</UnitPrice>
</Line>
</Invoice>
</Sales>
この xml ドキュメントがあり<Line>
、datagridview で請求書を選択するときに行 (タグ) を表示する必要があります。次のコードがありますが、メイン要素のサブ要素を表示する方法しか知りません"<Invoice>"
。"<Line>"
データグリッド内のそれぞれの要素のみを表示するクエリを実行する方法"<InvoiceNum>"
:
filepath1 = "C:\Users\Documents\Teste.xml"
Dim xml As XDocument = XDocument.Load(filepath1)
Dim query = From xe In xml.Descendants("Invoice")
Where xe.Element("InvoiceNum").Value = "153"
Select New With {
.Invoice = xe.Element("InvoiceNum").Value,
.Date = xe.Element("Date").Value
}
DataGridView1.DataSource = query.ToArray