0
<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 中选择发票时显示行(标签)。我有以下代码,但只知道如何显示 main element 的子元素"<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
4

0 回答 0