excel - VBA Importing multiple XML children under a single parent node -


i'm trying import data xml response excel sheet , having difficulty repeated child nodes under single parent node. need able import categoryid, categoryname, , categoryparentname lines each category. i've been able first 2 cant figure out categoryparentname since repeated. xml follows.

<getsuggestedcategoriesresponse xmlns="urn:ebay:apis:eblbasecomponents">    <timestamp>2010-01-19t22:08:02.568z</timestamp>    <ack>success</ack>    <version>647</version>    <build>e647_core_bundled_10438248_r1</build>    <suggestedcategoryarray>      <suggestedcategory>        <category>          <categoryid>18871</categoryid>          <categoryname>memory cards</categoryname>          <categoryparentid>625</categoryparentid>          <categoryparentid>3327</categoryparentid>          <categoryparentid>18866</categoryparentid>          <categoryparentname>cameras & photo</categoryparentname>          <categoryparentname>camera accessories</categoryparentname>          <categoryparentname>digital camera accessories</categoryparentname>        </category>        <percentitemfound>4</percentitemfound>      </suggestedcategory>      <suggestedcategory>        <category>          <categoryid>48629</categoryid>          <categoryname>color</categoryname>          <categoryparentid>293</categoryparentid>          <categoryparentid>14948</categoryparentid>          <categoryparentid>48633</categoryparentid>          <categoryparentid>48638</categoryparentid>          <categoryparentid>48628</categoryparentid>          <categoryparentname>electronics</categoryparentname>          <categoryparentname>gadgets</categoryparentname>          <categoryparentname>surveillance</categoryparentname>          <categoryparentname>surveillance cameras</categoryparentname>          <categoryparentname>wired cameras</categoryparentname>        </category>        <percentitemfound>4</percentitemfound>      </suggestedcategory>

here's attempt vba code. appreciated!

sub categoryresponse()  outputrow = sheet1.range("e1") + 7            nodes = "getsuggestedcategoriesresponse/suggestedcategoryarray/suggestedcategory"  each cat in responseitem.selectnodes(nodes)     outputcol = 3     sheet1.range("a" & outputrow).value = cat.selectsinglenode("percentitemfound").text     sheet1.range("b" & outputrow).value = cat.selectsinglenode("category/categoryid").text               nodes1 = "getsuggestedcategoriesresponse/suggestedcategoryarray/suggestedcategory/categoryparentname"     each par in responseitem.selectnodes(nodes1)        sheet1.cells(outputrow, outputcol).value = par.selectsinglenode("categoryparentname").text        outputcol = outputcol + 1     next par          sheet1.cells(outputrow, outputcol).value = ust.selectsinglenode("category/categoryname").text     outputrow = outputrow + 1  next ust    end sub

nodes1 should created relative current node in for each cat ... loop , not relative responseitem. try:

nodes1 = "category/categoryparentname" each par in cat.selectnodes(nodes1)    sheet1.cells(outputrow, outputcol).value = par.text    outputcol = outputcol + 1 next par 

you want select categoryparentname nodes relate current suggestedcategory node. original code have returned of categoryparentnames (which matched selectnodes expression) regardless of suggestedcategory node related to


Comments