How I can read all Attributes from a XML with VBA? -


i got webservice xml. declared "domdocument". xml. want read attributes named "zip".

<?xml version="1.0" encoding="utf-8" ?>  <location>   <cities>    <city zip="8355">aadorf</city>     <city zip="5000">aarau</city>     <city zip="5004">aarau</city>     <city zip="5032">aarau rohr</city>     <city zip="3270">aarberg</city>     <city zip="4663">aarburg</city>     <city zip="4912">aarwangen</city>     <city zip="8607">aathal-seegräben</city>     <city zip="8522">aawangen</city>     <city zip="1657">abländschen</city>     <city zip="5646">abtwil ag</city>     <city zip="9030">abtwil sg</city>    </cities> <location> 

with...

private sub workbook_open()      dim integer     dim numberofelements integer     dim city string     dim xmlurl string     dim xmldoc new domdocument      xmlurl = "http://localhost:62231/datahandling.asmx/getallcities"     xmldoc.async = false      if xmldoc.load(xmlurl) = false         msgbox ("xml load error")     else          numberofelements = xmldoc.getelementsbytagname("city").length          = 0 numberofelements - 1              city = xmldoc.selectsinglenode("//cities/city").attributes.getnameditem("zip").text              city = city & " " & xmldoc.getelementsbytagname("city").item(i).text              tabelle2.cells(i + 3, 1).value = city          next      end if  end sub 

i innertextes elements "city". everytime same attribute "8355".

city = xmldoc.selectsinglenode("//cities/city").attributes.getnameditem("zip").text 

this line should different, don't know how can loop threw whole xml read every single attrbute.

xmldoc.selectsinglenode("//cities/city") selects first node. cannot magically select next node every time, have read mind that.

private sub workbook_open()   dim city string   dim xmlurl string   dim xmldoc new domdocument   dim n ixmldomnode   dim long    xmlurl = "http://localhost:62231/datahandling.asmx/getallcities"   xmldoc.async = false    if not xmldoc.load(xmlurl)     msgbox "xml load error"   else      each n in xmldoc.selectnodes("//cities/city")       city = n.attributes.getnameditem("zip").text        city = city & " " & n.text        tabelle2.cells(i + 3, 1).value = city       = + 1     next    end if  end sub 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -