Hvordan præsenterer jeg attributer som redigerbare data.
Jeg kan ikke finde ud af at gennemløbe en xml-fil, så attributerne bliver præsenteret som records. Formålet er at man skal kunne redigere eller delete hver record.Det er denne kode, der er brug for at korrekse og måske også den efterfølgende attribut-præsentation:
<%
for i = 0 to xmlcontents.ChildNodes.attributes.length - 1
set xmlcontent = xmlcontents.ChildNodes(i).attributes %>
Den kommer igen længere nede i koden, men først her lige xml-filen.
<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>
Og her aspfilen.
<%
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>
<%
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>
