?
Solved

XML Parsing Classic ASP

Posted on 2016-09-30
5
Medium Priority
?
86 Views
Last Modified: 2016-09-30
Hi

I'm trying to write a classic ASP script that sends an xml request to an API and parses the response into variables. The send works and the response (.responseText) is the following:


<response status='ok'>
<serviceRequestList>
<serviceRequest>
  <customerContactEmail>aaa@@aaa.com</customerContactEmail>
  <customerName>ABC Corp</customerName>
  <description>Misc Job #1</description>
  <detailedDescription>Job work</detailedDescription>
  <serviceRequestId>4586</serviceRequestId>
  <status>Open</status>
  <type>Service</type>
</serviceRequest>
<serviceRequest>
  <customerContactEmail>aaa@@aaa.com</customerContactEmail>
  <customerName>ABC Corp</customerName>
  <description>Misc Job #2</description>
  <detailedDescription>work on LPTP issues and syncing AD to Google Apps</detailedDescription>
  <serviceRequestId>4686</serviceRequestId>
  <status>Open</status>
  <type>Service</type>
</serviceRequest>
<serviceRequest>
  <customerContactEmail>aaa@@aaa.com</customerContactEmail>
  <customerName>ABC Corp</customerName>
  <description>L2TP Transition and GAPS sync</description>
  <detailedDescription>wJob work</detailedDescription>
  <serviceRequestId>4587</serviceRequestId>
  <status>Open</status>
  <type>Service</type>
</serviceRequest>
</serviceRequestList>
</response>



However when trying to parse the result I'm unable to get the information I need.   From the above response I'd like to extract the customerContactEmail, customerName, description, detailedDescription, serviceRequestId, status, type tags into individual variables.

Ive tried many different methods, but I'm getting blank returns with no errors from everything I've tried.

Can someone please help!

Thanks
0
Comment
Question by:mizgroup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 41823771
here's an example that'll get you the first couple of fields:

xml = <your xml data>
Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")    
objXMLDoc.async = False    
objXMLDoc.load xml

Dim xmlServiceRequest       
For Each xmlServiceRequest In objXMLDoc.documentElement.selectNodes("/response/serviceRequestList/serviceRequest")
     Dim customerContactEmail : customerContactEmail = xmlServiceRequest.selectSingleNode("customerContactEmail").text   
     Dim customerName : customerName = xmlServiceRequest.selectSingleNode("customerName").text   
     Response.Write Server.HTMLEncode(customerContactEmail) & "<br>"
     Response.Write Server.HTMLEncode(customerName) & "<br>"   
Next   

Open in new window

0
 

Author Comment

by:mizgroup
ID: 41823794
@Big Monty thanks.. but i get the following error

oft VBScript runtime error '800a01a8'

Object required: 'objXMLDoc.documentElement'
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 41823856
sorry,

objXMLDoc.load xml

should be

objXMLDoc.loadXML xml
0
 

Author Closing Comment

by:mizgroup
ID: 41823891
Thank you very much, ive been breaking my head on this for two days!
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41823892
glad to help :)
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question