Solved

How to get specific tag value using XML DOM

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

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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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