ASP Classic - XML Dom

后端 未结 3 397
别跟我提以往
别跟我提以往 2020-12-17 03:13

I\'ve got the unpleasurable task of working on a Classic ASP site (VBSCRIPT) and need to parse out the following information in a loop.


  

        
相关标签:
3条回答
  • 2020-12-17 03:29

    Switch to using xpath instead and it will be much easier.

    Dim nodes
    nodes = objXML.selectNodes( "//products" )
    
    Dim images
    
    For each node in nodes
        Response.Write( "<ul>" )
        Response.Write( "<li>Ref: " + node.selectNodes( "@ref" ).Text + "</li>" )
        images = node.selectNodes( "images/image" )
        For each image in images
            Response.Write( "<li>Image: " + image.selectNodes( "@ref" ).Text + "</li>" )
        Next
        Response.Write( "</ul>" )
    Next
    

    I'm a JScript ASP coder, like you not done VBScript for an age so the above "might" need a bit of polish (I had to strip out all the ";" at the end of the all the lines, such is the habit of adding them) but should point you in the right direction at least.

    Hope that helps.

    0 讨论(0)
  • 2020-12-17 03:41

    Try the following command to get the attribute value specifically for the image node:

    node.Attributes.getNamedItem("ref").Text 
    
    0 讨论(0)
  • 2020-12-17 03:45

    Yeah, having to work in classic ASP occasionally transports me back to the Stone age too... I feel your pain!

    IIRC, in your second code snippet, you just need to add :

    for each node in childNodes
      Response.Write node.nodeName & "  =  " & node.text & "<br />" & vbCrLf
      '***Add the following:
      For Each att in node.Attributes
        Response.Write att.Name & "  =  " & att.text & "<br />" & vbCrLf
      Next
    next
    
    0 讨论(0)
提交回复
热议问题