Solved

How to get specific tag value using XML DOM

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

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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 - show results in 2 columns 5 32
Post xml via PHP Soap Client 3 48
XML SQL 8 25
XML Removal- Powershell 4 25
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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