Solved

How to get specific tag value using XML DOM

Posted on 2014-09-29
5
288 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

23 Experts available now in Live!

Get 1:1 Help Now