I have a XML payload as follows
<tsResponse>
<sites>
<site id="site-id" name="site1-name" contentUrl="site1-content-url" />
<projects>
<project id="project1-id" name="project1-name"/>
<project id="project2-id" name="project2-name"/>
</projects>
</site>
<site id="site2-id" name="site2-name" contentUrl="site2-content-url" />
<projects>
<project id="project3-id" name="project3-name"/>
<project id="project4-id" name="project4-name"/>
</projects>
</site>
</sites>
</tsResponse>
I can loop through each site, collecting each site ID, name and contentURL as I go along with the following
Set oXML = Server.CreateObject("Microsoft.XMLDOM")
oXML.LoadXML(postResponse) ' sXML is a variable containing the content of your XML file
For Each oNode In oXML.SelectNodes("/tsResponse/sites/site")
sID = oNode.GetAttribute("id")
sName = oNode.GetAttribute("name")
sContentURL = oNode.GetAttribute("contentUrl")
Next
Set oXML = Nothing
However how do I pick up each project ID and name within each site? Would I need another For Loop within the existing one or is that too inefficient? How do I loop through where a particular attribute = X?
No comments:
Post a Comment