▽1
●
a-kuma3 ●333ポイント ベストアンサー |
For Each で回すとか、
Set Amounts = xml_data.getElementsByTagName("Amount") For Each e In Amounts MsgBox e.Text Next
For で回すとか。
Set Amounts = xml_data.getElementsByTagName("Amount") For i = 0 To Amounts.Length - 1 MsgBox Amounts(i).Text Next
「Condition」と「Amount」はひもづけて取り出したいです。
また、「Offer」ブロックはここでは2つですが、増減します。
では、こんな感じで。
Set offer = xml_data.getElementsByTagName("Offer") For Each e In offer Set amount = e.getElementsByTagName("Amount") Set condition = e.getElementsByTagName("Condition") MsgBox amount(0).Text MsgBox condition(0).Text Next
Offer 要素を取り出して、For Each で回し、その下にある Amount と Condition を getElementsByTagName() メソッドで取り出してます。
Offer の下に、Amount や Condition がひとつだけだというのを前提にしてます。
# ポイントは 100pt でも、全然 OK ですよん♪
「Condition」と「Amount」はひもづけて取り出したいです。
また、「Offer」ブロックはここでは2つですが、増減します。
さしあげるポイントは「100ポイント」ではなく、「300ポイント」に変更いたします。
XPath 形式で書いてみました。
Option Explicit Sub ShowXmlData() Dim xml_data Set xml_data = CreateObject("Msxml2.DOMDocument.6.0") xml_data.Load "sample.xml" Dim cond Dim amt Dim nodes Set nodes = xml_data.SelectNodes("/Offers/Offer") Dim node For Each node In nodes Set cond = node.SelectSingleNode("OfferAttributes/Condition") Set amt = node.SelectSingleNode("OfferListing/Price/Amount") Debug.Print "Condition = [" & cond.Text & "], Amount = [" & amt.Text & "]" Next End Sub
<実行結果> Condition = [New], Amount = [2100] Condition = [Used], Amount = [800]
<参考情報>
■ MSXML DOM の SelectNodes メソッドで XPath クエリを使用する方法
http://support.microsoft.com/kb/288913/ja