采用asp遍历XML文档 [英] Traverse XML document using asp

查看:226
本文介绍了采用asp遍历XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到,如果某个元素是一个XML文件present,如果是,将其删除。不过,我不断收到此错误:

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'

我的code是这样的:

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 ((NodeList(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")

%>

和XML文件是这样的:

And the XML file looks like this:

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

的形式是填充了这个相同的XML文件中的下拉菜单。
有谁知道这可能是造成这个错误?

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

这篇关于采用asp遍历XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆