Solved

How to get specific tag value using XML DOM

Posted on 2014-09-29
5
275 Views
Last Modified: 2014-09-29
I have the following XML:

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/insertRecords">
  <result>
    <row no="3">
      <success> <code>2000</code>
        <details>
          <FL val="Id">1240444000000100001</FL>
          <FL val="Created Time">2014-09-26 00:47:16</FL>
          <FL val="Modified Time">2014-09-26 00:47:16</FL>
          <FL val="Created By">
            <![CDATA[John Smith]]>
          </FL>
          <FL val="Modified By">
            <![CDATA[John Smith]]>
          </FL>
        </details>
      </success>
    </row>
  </result>
</response>
I would like to extract the specific value in the following tag:
<FL val="Id">1240444000000100001</FL>

Hence I need to extract 1240444000000100001 from tag <FL> with attribute val="Id".

I am using ASP classic and XML DOM. I have made a start with the code here:
Dim xmlstr, xmlObj

	xmlstr= "<?xml version=""1.0"" encoding=""UTF-8"" ?>" &_
			"<response uri=""/crm/private/xml/Leads/insertRecords"">" &_
			"  <result>" &_
			"	<row no=""3"">" &_
			"	  <success>" &_
			"       <code>2000</code>" &_
			"		<details>" &_
			"		  <FL val=""Id"">1240444000000100001</FL>" &_
			"		  <FL val=""Created Time"">2014-09-26 00:47:16</FL>" &_
			"		  <FL val=""Modified Time"">2014-09-26 00:47:16</FL>" &_
			"		  <FL val=""Created By"">" &_
			"			<![CDATA[John Smith]]>" &_
			"		  </FL>" &_
			"		  <FL val=""Modified By"">" &_
			"			<![CDATA[John Smith]]>" &_
			"		  </FL>" &_
			"		</details>" &_
			"	  </success>" &_
			"	</row>" &_
			"  </result>" &_
			"</response>"
			
	Set xmlObj = Server.CreateObject("Microsoft.XMLDOM")
	xmlObj.async = False
	xmlObj.setProperty "ServerHTTPRequest", True
	xmlObj.LoadXML(xmlstr)
	If xmlObj.parseError.errorCode <> 0 Then
		'### NOTHING
	End If
	


	Set xmlObj = Nothing

Open in new window

0
Comment
Question by:mike99c
  • 3
  • 2
5 Comments
 

Author Comment

by:mike99c
ID: 40349474
OK I managed to get it to work using this:
	Set TheNode    = xmlObj.documentElement.selectNodes("//response/result/row/success/details/FL")
	response.write "Node value: " & TheNode(0).text

Open in new window

However this makes no reference to the specific attribute val="Id" and simply takes the text from the first FL tag. I want it to extract the text from the FL tag where val="Id" irrespective of which order the tag is listed.
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40349589
This should do it:
	TheValue = "Id"
	Set TheNode    = xmlObj.documentElement.selectNodes("//response/result/row/success/details/FL[@val=""" & TheValue & """]")
	If TheNode.length > 0 then
	  response.write "Node value: " & TheNode(0).text	
	Else
	  response.write "Node not found"
	End If

Open in new window

0
 

Author Comment

by:mike99c
ID: 40349601
Thanks Robert that worked. I will give you all the points now.

Any chance you could help me with my other open  post here:
http://www.experts-exchange.com/Programming/Languages/Scripting/ASP/Q_28526393.html

I am trying to figure out how to check if a tag contains child tags.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 40349703
Ok, great. I'm a having a look at your other question but it's a bit of an overflow of information to see what the current status is. Gimme some time and I'll post there if I have something or here if I don't.
0
 

Author Comment

by:mike99c
ID: 40349773
OK thanks Robert, it would be best if you can post it on that specific link so I can assign you the points.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now