很抱歉,如果描述很差,但我不知道該怎麼把這個... 但這裏是XML結構的例子XML到數據集 - 問題找到什麼數據行包含一個DataTable
<?xml version=」1.0」 encoding=」UTF-8」>
<Response xmlns="http://www.blah.com">
<searchResult>
<info>
<firstName>John</firstName>
<lastName>Doe</lastName>
<totalCharges>100.00</totalCharges>
<nonPaymentCode>99999</nonPaymentCode>
</info>
<info>
<firstName>Susan</firstName>
<lastName>Doe</lastName>
<totalCharges>1000.00</totalCharges>
<errorCodes>
<errorCode>12345</errorCode>
</errorCodes>
</info>
<info>
<firstName>Peter</firstName>
<lastName>Doe</lastName>
<totalCharges>10.00</totalCharges>
<errorCodes>
<errorCode>12345</errorCode>
<errorCode>54321</errorCode>
<errorCode>85246</errorCode>
</errorCodes>
</info>
</searchResult>
</claimInquiryResponse>
我已經將其轉換爲數據集,以便將信息作爲數據表訪問。 但我的問題是試圖獲得錯誤代碼。我試圖通過檢查表格的關係來解決這個問題。因爲我必須弄清楚哪些錯誤代碼與哪個人相關聯,以便正確顯示它們。我無法控制XML結構,並且所有內容都是可選的,以便減少多餘的帶寬,因此現在不能改變它。但這裏是我所做的一個例子:
For Each rel As DataRelation In ds.Tables(i).ChildRelations
If rel.Nested Then
Dim temp As New DataTable
temp = rel.ChildTable
For Each relationship As DataRelation In temp.ChildRelations
For Each row As DataRow In relationship.ChildTable.Rows
For Each column As DataColumn In relationship.ChildTable.Columns
rowValues &= column.ColumnName & "-" & row(column.ColumnName) & "-" & relationship.RelationName & vbCrLf
Next
Next
Next
End If
Next
這給了我errorCodes表內的數據的實際值。但我無法弄清楚如何將其鏈接回與其關聯的行/人。關係產生的索引是建立在它們發生的位置(例如,susan的錯誤代碼將爲0,並且peter它將爲1),而不涉及它們在XML中的位置。
我要麼做錯了這個或錯誤地看着這個數據。 我知道我可以使用XML閱讀器來獲取所有這些信息,但數據已經存在於數據集中,我覺得要學習新東西。所以只建議它作爲最後的手段請。
在此先感謝!
無效的xml是製作原始帖子時的複製/粘貼錯誤。它結構良好。 – John 2011-03-03 20:19:44