开发者

Traverse XML document using asp

I'm trying to find if a certain element is present in a XML file and if it is, remove it. However I keep getting this error:

Description: Type mismatch: 'NodeList'

My code looks like this:

<%@ Language=VbScript%>
<%

Dim address

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.load (Server.MapPath("XML/sensor.xml"))

Set Root = XMLDoc.documentElement 

Set NodeList = Root.getElementsByTagName("sensor")

For Each i In NodeList

    if ((Nod开发者_Python百科eList(i).getElementsByTagName("Address")(0).childNodes(0).nodeValue)=request.form("remove_address")) then
    NodeList.parentNode.removeChild NodeList 
    End if
Next



NodeList.parentNode.removeChild NodeList 
xmlDoc.Save "\www./XML/sensores.xml"

Response.Redirect("remove_sensor_modbus.html")

%>

And the XML file looks like this:

<?xml version="1.0"?>
<sensors>
<sensor>
    <Address>40000</Address>
</sensor>
<sensor>
    <Address>46999</Address>
</sensor>
</sensors>

The form is a dropdown menu populated with this same XML file. Does anyone knows what could be causing this error?


It looks like you have several errors in your loop. Try this:

Dim removeAddress
Set removeAddress = Request.Form("remove_address")

For Each sensorNode In NodeList
    Dim addressNode
    Set addressNode = sensorNode.GetElementsByTagName("Address")(0)

    If (addressNode.Text = removeAddress) Then
        sensorNode.RemoveChild(addressNode)
    End if
Next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜