Results 1 to 5 of 5

Thread: How to Parse XML in ASP

  1. #1
    Join Date
    Apr 2009
    Posts
    569

    How to Parse XML in ASP

    Hi ,

    I am using ASP as a business logic in one of my project. I want to parse XML code in ASP, But it reflects with an error :
    Code:
    Microsoft VBScript runtime error '800a01a8'
    Object required: 'documentElement'
    My ASP code is :

    Code:
     Dim xmlDoc123
     Set xmlDoc123 = Server.CreateObject("Microsoft.XMLDOM")
     xmlDoc.load("http://mysite.com/api/xml?action=login&login=abc@xyz.com&password=123456")
    Parse XML
    if xmlDoc.parseError.errorcode <> 0 then
          ' oops error in xml
          Response.Write("XML Error...<br>")
          else
         ' get xml data
    Response.Write(xmlDoc123.documentElement.childNodes(0).attributes.getNamedItem("code").nodeValue)
          end if
    and my XML code is

    Code:
       <?xml version="1.0" encoding="utf-8"?>
          <results>
          <status code="value"/>
          </results>
    Please suggest.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to Parse XML in ASP

    You need to try this code, it will work with me.

    Code:
    <%
    Option Explicit
    Response.Buffer = True
    
    Dim xml123
    	Set xml123 = Server.CreateObject("Microsoft.XMLDOM")
    	xml123.async = False
    	xml123.load (Server.MapPath("mypage.xml"))
    
    Dim title123, heading123, paragraph123, testHTML123
    	title123 = xml123.documentElement.childNodes(0).text
    	heading123 = xml123.documentElement.childNodes(1).text
    	paragraph123 = xml123.documentElement.childNodes(2).text
    	testHTML123 = xml123.documentElement.childNodes(3).text
    
    	Set xml123 = Nothing
    %>
    <html>
    <head>
    	<title123><%= title %></title123>
    </head>
    <body>
    <h3 align="center"><%= heading123 %></h3>
    <p align="center"><% = paragraph123 %></p>
    <div align="center"><%= testHTML123 %></div>
    </body>
    </html>

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    How to Parse XML in ASP

    I parse XML using XSL stylesheets via ASP in y project, Try it and reply.

    Code:
    <%
    xmlf = "example123.xml"
    stylef = "example123.xsl"		
    set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
    set xslDoc = Server.CreateObject("Microsoft.XMLDOM")	
    xmlDoc.load(Server.Mappath(xmlf))
    xslDoc.load(Server.Mappath(stylef))
    Response.Write(xmlDoc.transformNode(xslDoc))
    %>

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    How to Parse XML in ASP

    There are several ways that you parse XML code in ASP. Try this.

    ASP Syntax
    Code:
    set objXMLRoot = xmlDoc.selectSingleNode("//results123/data123")
    set objXMLRoot = xmlDoc.selectSingleNode("//results123/data123")
    if not (objXMLRoot is nothing) then
    for each objNode in objXMLRoot.childNodes()
    response.write objNode.text
    next
    end if

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    How to Parse XML in ASP

    I have tried to pull out some nodes from an xml string, lets try the below code.

    Code:
    Set xml123  = Server.CreateObject("MSxml2.FreeThreadedDomDocument.3.0")
    xml.async = False
    xml.loadxml(xmlhttp.responseText)
    Set root = xml.documentElement
    Set hotelname123 = root.selectNodes("abddef")
    clientid123 = name.selectSingleNode("response/customer/clientId123").text
    totalrate123 = name.selectSingleNode("response/rateinfo/totalRate123").text
    hotelid123 = name.selectSingleNode("request/hotelID123").text
    confid123 = name.selectSingleNode("response/confirmationNumber123").text
    Next
    response.write(clientid123 & totalrate123 & hotelid123 & confid123)

Similar Threads

  1. dropdown list and parse xml!
    By bill90 in forum Software Development
    Replies: 2
    Last Post: 07-03-2012, 08:23 AM
  2. How to add parse in scanner in java?
    By MAGAR in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 04:30 PM
  3. How to parse XML in J2ME
    By Abigail101 in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 03:39 AM
  4. How to Parse CSV file using PERL
    By Xena in forum Software Development
    Replies: 3
    Last Post: 31-08-2009, 10:38 AM
  5. PHP Parse error: parse error unexpected $ in main.php on line 12
    By ΘN-TH3-ЯΘCKZ in forum Software Development
    Replies: 3
    Last Post: 20-08-2009, 06:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,484,633.09423 seconds with 17 queries