Very good code, it is convenient for friends who use xml as a database. Now they have an xml with the following format:
Copy the code code as follows:
<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>
I use ASP to query id=2 and enter the value of the corresponding name. How do I write it? Using ASP
Copy the code code as follows:
dimid
id=2
Set objXML = Server.CreateObject(Microsoft.XMLDOM)
objXML.Load(server.MapPath(filePath))
Set objNodes = objXML.selectSingleNode( date/item[id = ' & id & '] )
//To query name, just change the above id to name.
How to query ID and output related name?
Copy the code code as follows:
dimid
id=2
Set objXML = Server.CreateObject(Microsoft.XMLDOM)
objXML.Load(server.MapPath(filePath))
Response.Write(objXML.selectSingleNode( date/item[id = ' & id & ']/name ).text)
If there are duplicate IDs, the call is:
Copy the code code as follows:
Set objNodes = objXML.selectNodes( date/item[id = ' & id & '] )
Perform loop output.