現在有一個xml,格式如下:
<date>
<item>
<id> 1 </id>
<name> ABC </name>
</item>
<item>
<id> 2 </id>
<name> cde </name>
</item>
<item>
<id> 3 </id>
<name> efg </name>
</item>
</date>
我用ASP查詢id=2,輸入相應name的值,請問一下怎麼寫?用ASP的
dim id
id= "2 "
Set objXML = Server.CreateObject( "Microsoft.XMLDOM ")
objXML.Load(server.MapPath(filePath))
Set objNodes = objXML.selectSingleNode( "date/item[id = ' " & id & " '] ")
//查詢name話把上面的id變為name就可以了
查詢ID,怎麼輸出相關的name?
dim id
id= "2 "
Set objXML = Server.CreateObject( "Microsoft.XMLDOM ")
objXML.Load(server.MapPath(filePath))
Response.Write(objXML.selectSingleNode( "date/item[id = ' " & id & " ']/name ").text)
如果ID有重復的,調用就是:
Set objNodes = objXML.selectNodes( "date/item[id = ' " & id & " '] ")
進行循環輸出。