How do I get this value?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pheddy
    New Member
    • Dec 2008
    • 80

    How do I get this value?

    Hello :D

    Im getting into trouple with this one. Do anybody know how to extract the ID (<product id="506343242"> ) in this XML file?

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="oemPriceXMLList.xsd">
    
    <group name="">
    </group>
    <group name="Some Soft">
    <product id="506343242">
    <name>Adobe Acrbobat 9</name>
    <stock>Yes</stock>
    <weight>0.5</weight>
    <model>6504543534</model>
    <shortDescription>DESCRIPTION</shortDescription>
    <manufacturerName>Adobe</manufacturerName>
    <manufacturerURL>http://www.adobe.com/</manufacturerURL>
    <price>300</price>
    I can retrieve the other values by using xmlDOC.document Element.selectN odes("//products/group/product/stock")

    I am using xmlDOC in an ASP script..

    Thanks!
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    xmlDoc.getEleme ntsByTagName("p roduct ")[0].getAttribute(" id")

    Comment

    • Pheddy
      New Member
      • Dec 2008
      • 80

      #3
      I got this error when using
      Code:
      objNodeList9 = xmlDoc.getElementsByTagName("product")[0].getAttribute("id")
      Code:
      Microsoft VBScript compilation error '800a0401' 
      
      Expected end of statement 
      
      /xml.asp, line 42 
      
      Set objNodeList9 = xmlDoc.getElementsByTagName("product")[0].getAttribute("id")
      So I tried:

      Code:
      xmlDoc.getElementsByTagName("product").getAttribute("id")
      But got this error

      Code:
      Microsoft VBScript runtime error '800a01b6' 
      
      Object doesn't support this property or method: 'getAttribute' 
      
      /xml.asp, line 42

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        This is gonna sound dumb, but are you missing a semicolon or other statement terminator?

        Also, in VBA, which is what I'm familiar with, the appropriate verb is "Let" for value assignment - "Set" is used for object assignment.

        Comment

        • Pheddy
          New Member
          • Dec 2008
          • 80

          #5
          .. No I cant find any of those error, maybe my version is somewhat wrong?

          I am using (in ASP)

          Code:
          Set HTTP 		= CreateObject("MSXML2.XMLHTTP")
          Set xmlDOC		= CreateObject("MSXML.DOMDocument")

          Comment

          • Oralloy
            Recognized Expert Contributor
            • Jun 2010
            • 988

            #6
            Did you try using Let, not Set?

            Code:
            Let objNodeList9 = xmlDoc.getElementsByTagName("product")[0].getAttribute("id")

            Comment

            • Pheddy
              New Member
              • Dec 2008
              • 80

              #7
              That dosnt work.. Anyother bids??

              Comment

              • jkmyoung
                Recognized Expert Top Contributor
                • Mar 2006
                • 2057

                #8
                What version of ASP?

                xmlDoc.SelectNo des("product/@id") OR
                xmlDoc.SelectSi ngleNode("produ ct/@id")

                Comment

                • Pheddy
                  New Member
                  • Dec 2008
                  • 80

                  #9
                  I am using Classic Asp.

                  Again I Get errors...

                  With

                  Code:
                    Set objNodeList9	= xmlDoc.SelectSingleNode("product/@id")
                      Response.Write objNodeList9(i).nodeValue & "<br>"
                  I get:

                  Code:
                  Microsoft VBScript runtime error '800a000d' 
                  
                  Type mismatch
                  And with

                  Code:
                    Set objNodeList9	= xmlDoc.SelectNodes("product/@id")
                      Response.Write objNodeList9(i).nodeValue & "<br>"
                  I get:

                  Code:
                  Microsoft VBScript runtime error '800a01a8' 
                  
                  Object required: '[object]'

                  Comment

                  • Pheddy
                    New Member
                    • Dec 2008
                    • 80

                    #10
                    So I found the answer!

                    Here it is:

                    Code:
                      Set objNodeList8	= xmlDOC.documentElement.selectNodes("//products/group/product/@id")
                        Response.Write objNodeList8(i).text & "<br>"
                    Thanks for all replies!

                    -Frederik

                    Comment

                    Working...