Solved

How to get specific tag value using XML DOM

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSL FO - text wrapping and empty spaces 1 38
ASP exit 10 20
IIS 7 and executing pages using localhost 16 14
href return to normal window 5 16
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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