How to get XML attribute value?

后端 未结 1 791
Set XmlDocument = Server.CreateObject(\"Msxml2.DOMDocument.3.0\")
XmlDocument.SetProperty \"ServerHTTPRequest\", True
XmlDocument.         


        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-24 04:14

    SelectSingleNode("price/text()") selects the text node (the "body" if you will) inside the tag. The nested text node doesn't have an attribute avail. Also, GetAttribute() doesn't return an object, so you must not use the Set keyword there.

    Change this:

    Set title = Item.SelectSingleNode("title/text()")
    S_title = Trim(title.data)
    
    Set price = Item.SelectSingleNode("price/text()")
    S_price = Trim(price.data)  
    response.Write S_title & S_price 
    
    Set Objavail = PRICE.GetAttribute("avail")
    S_avail = Objavail.value
    response.Write S_avail &"
    "

    into this:

    Set title = Item.SelectSingleNode("title")
    S_title = Trim(title.text)
    
    Set price = Item.SelectSingleNode("price")
    S_price = Trim(price.text)
    response.Write S_title & S_price 
    
    S_avail = price.GetAttribute("avail")
    response.Write S_avail &"
    "

    0 讨论(0)
提交回复
热议问题