将具有多个表的XML导入VB.NET

时间:2016-10-16 19:59:38

标签: xml vb.net

所以我有以下.XML文件......

<?xml version="1.0" encoding="UTF-8"?>
<PPG>
<Header>
  <Protocol>
     <Message>MixDataInterface</Message>
     <Name>PPG</Name>
     <Version>1.3.0</Version>
  </Protocol>
  <Transaction>
     <TransactionID>2577f125-663d-4351-909c-02fab90f21fd</TransactionID>
     <TransactionDate>2016-10-13T22:48:09</TransactionDate>
  </Transaction>
  <ShopInfo>
     <PPGShopID />
     <ShopID>DB</ShopID>
     <ShopName>TRAXX</ShopName>
  </ShopInfo>
</Header>
<MixDataInterface>
  <ROData>
     <ROCount>5</ROCount>
     <RepairOrders>
        <RO>
           <ROCounter>1</ROCounter>
           <RONumber>UNASSIGNED</RONumber>
           <Notes />
           <Undercoat>False</Undercoat>
           <Clearcoat>False</Clearcoat>
           <Basecoat>True</Basecoat>
           <TotalLiquidCost>0.00</TotalLiquidCost>
           <TotalSundryCost>0.00</TotalSundryCost>
           <MixCount>1</MixCount>
           <Mixes>
              <Mix>
                 <MixCounter>1</MixCounter>
                 <MixRONumber>UNASSIGNED</MixRONumber>
                 <MixedDate>2016-10-05T00:00:00</MixedDate>
                 <MixedBy />
                 <MixedByEmployeeID />
                 <MixCost>0.00</MixCost>
                 <PPGBrandCode>7EFBB</PPGBrandCode>
                 <ColorMixDescription>AQUABASE PLUS (AQU+ BC Solid) 7EFBB Prime (BIANCO BIANCO , BIANCO NEVE)</ColorMixDescription>
                 <FormulaType>Standard</FormulaType>
                 <ComponentCount>4</ComponentCount>
                 <Components>
                    <Component>
                       <ComponentCounter>1</ComponentCounter>
                       <ComponentRONumber>UNASSIGNED</ComponentRONumber>
                       <ComponentCode>P990-8900</ComponentCode>
                       <ComponentDescription>BRILLIANT WHITE</ComponentDescription>
                       <ComponentCost>0.00</ComponentCost>
                       <ComponentWeightApplied>0.00000</ComponentWeightApplied>
                       <ComponentWeightTarget>179.30470</ComponentWeightTarget>
                       <ComponentDensity>1.21300</ComponentDensity>
                    </Component>
                 </Components>
              </Mix>
           </Mixes>
           <SundryCount>0</SundryCount>
        </RO>
      </RepairOrders>
  </ROData>
</MixDataInterface>
</PPG>

我希望将其导入VB.NET。我找到了以下MSDN文章https://msdn.microsoft.com/en-us/library/ekw4dh3f.aspx,但示例.XML文件只有一个表,所以当我将它应用到我的文件时,我会收到错误。

有人可以帮我解决如何将此文件导入数据集的问题。

后来我需要弄清楚如何更新数据集,因为.XML会更新(我别无选择,我的唯一数据来源就是这个.XML)但是现在我很高兴能够导入文件。

1 个答案:

答案 0 :(得分:0)

@jdweng是正确的,这里有一些代码可以帮助您探索导入的内容:

    Dim ds As New DataSet
    Dim sr As New StringReader(sPostXMLData)
    ds.ReadXml(sr)
    For Each t As DataTable In ds.Tables
        Debug.Print(t.TableName)
    Next

表: 头 协议 交易 ShopInfo MixDataInterface RODATA RepairOrders RO 混合 混合 组件 成分

没用。查看更多用于解析数据的XML特定工具。