Link to home
Start Free TrialLog in
Avatar of SimonAdrian
SimonAdrian

asked on

What is the precise childnode-path to loop xml-file?

<%
for i = 0 to xmlcontents.ChildNodes.attributes.length - 1
set xmlcontent = xmlcontents.ChildNodes(i).attributes %>

this code is my attempt to convert another fine working looping to this need (see attached snippet of the original code).

I want to present some xml-attributes as records, but I cant quite figure out how to loop through the xml-file, that looks like this:
 
<map>
        <positions>
                <position id="1" xPosition="80" yPosition="80" xWidth="120" yHeight="60">Bruxelles</position>      
                <position id="2" xPosition="10" yPosition="60" xWidth="100" yHeight="90">New York</position>
                <position id="3" xPosition="100" yPosition="180" xWidth="200" yHeight="20">Los Angeles</position>
                <position id="4" xPosition="150" yPosition="150" xWidth="120" yHeight="30">Singapore</position>
        </positions>
</map>

I have tried to change a code that was doing the job with a xml-file that was formatted with nodeelements ( see attached snippet).
The purpose is to present records which can be edited and deleted.

<%
dim objXML
set objXML = server.CreateObject("Microsoft.FreeThreadedXMLDOM")

if request.QueryString("delete") <> "" then
objXML.Load(xmlpath)
set remove = _
objXML.childnodes(0).childnodes(1).childnodes(request.QueryString("delete"))
objXML.childnodes(0).childnodes(1).removeChild(remove)
objXML.save(xmlpath)
end if

objXML.Load(xmlpath)
set xmlcontents = objXML.DocumentElement.selectSingleNode("positions")
%>

<html>
<body>
  <table width="180">
    <tr>
      <th width="80">Options</th>
      <th width="20">id</th>
      <th width="20">xPosition</th>
      <th width="20">yPosition</th>
      <th width="20">xWidth</th>
      <th width="20">yHeight</th>
         </tr>

'The solution I want is solving the code below.

    <%
for i = 0 to xmlcontents.ChildNodes.attributes.length - 1
set xmlcontent = xmlcontents.ChildNodes(i).attributes %>
    <tr>
      <td><a href="editcontent.asp?id=<%= i+1%>">Edit</a> - <a href="?delete=<%= i%>">Delete</a></td>
      <td><%= xmlcontent.ChildNodes(i).attributes.id %></td>
      <td><%= xmlcontent.ChildNodes(i).attributes.xPosition %></td>
      <td><%= xmlcontent.ChildNodes(i).attributes.yPosition %></td>
      <td><%= xmlcontent.ChildNodes(i).attributes.xWidth %></td>
      <td><%= xmlcontent.ChildNodes(i).attributes.yWidth %></td>
     </tr>
    <% next %>
   </table>
  </body>
</html>

I have to stress that Im not interested in doing it any other way. I want the rest of the code to be precisely as it is. No VB-script solution or any other ways.
Just make the topcode usable to the script as the codesnippet does to its xml-file.

<%
for i = 0 to xmlcontents.ChildNodes.length - 1 
set xmlcontent = xmlcontents.ChildNodes.item(i)
%>
    <tr> 
      <td><a href="editcontent.asp?id=<%= i+1%>">Edit</a> - <a href="?delete=<%= i%>">Delete</a></td>
      <td><%= xmlcontent.ChildNodes.item(1).text%></td>
      <td><%= xmlcontent.ChildNodes.item(2).text%></td>
      <td><%= xmlcontent.ChildNodes.item(3).text%></td>
      <td><%= xmlcontent.ChildNodes.item(4).text%></td>
      <td><%= xmlcontent.ChildNodes.item(5).text%></td>
    </tr>
    <% next %>

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image

>> No VB-script solution or any other ways
If you don't want vbscript, then what is this?

for i = 0 to xmlcontents.ChildNodes.length - 1
...
next
>>No VB-script solution or any other ways.<<
Than why post it here?  Perhaps you should post it here: https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/#browseZones
Avatar of SimonAdrian
SimonAdrian

ASKER

Sorry, I just want to stress, that I  want the path changed, not the entire script.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Update: You don't need this:
Response.Write xmlcontents.childNodes.length

(I used it for debugging)
Im gratefull, thanks.