Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coldfusion and XML - need assistance reading XML values - am desperate!

Posted on 2006-10-31
3
Medium Priority
?
141 Views
Last Modified: 2013-12-24
I'm afraid I have virtually no experience working with XML & Coldfusion, so any advice that anyone can provide would be great.  I am trying to grab a web page and get the certain values into a database.  The web page I am calling with <cfhttp> is a php file that returns contents as XML.

i.e.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE workspace PUBLIC "-//workname//DTD workspace 1.0" "http://localhost:8080/workspace/p.dtd">
<working type="d">
          <off><u>132915</u></off>
</working>
<working type="d">
    <on><u>132915</u></on>
</working >
<working type="d">
          <off><u>13112</u></off>
</working>

I am totally baffled as to how to accomplish getting the values for which numbers come across as <off></off> and which come across as <on></on> read out of the xml and into a usuable format.  If you need more information or I am not clear on this, please just let me know!

Thanks!
0
Comment
Question by:questhaven
[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
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
Marco_van_den_Oever earned 2000 total points
ID: 17848861
Hi there, maybe it's easier to post the php page, it's very important that the page is formatted correctly and wrapped up correctly with tags (like: <item><grabthis></grabthis></item> and maybe exported to .xml format, then you should request the page like:

<!--- Retrieve the RSS document --->
<cfhttp url="http://wwwphppage.php" method="get">

<!--- Validation flag --->
<cfset XMLVALIDATION = true>

<cftry>
<!--- Create the XML object --->
<cfset objRSS = xmlParse(cfhttp.filecontent)>

<cfcatch type="any">
<!--- If the document retrieved in the CFHTTP
is not valid set the validation flag to false. --->
<cfset XMLVALIDATION = false>
</cfcatch>
</cftry>

<cfif XMLVALIDATION>
<!--- If the validation flag is true continue parsing --->

<!--- Set the XML Root --->
<cfset XMLRoot = objRSS.XmlRoot>

<!--- Retrieve the document META data --->
<cfset doc_grabthis = XMLRoot.channel.grabthis.xmltext>

<!--- Output the meta data in the browser --->

<!--- Retrieve the number of items in the channel --->
<cfset Item_Length = arraylen(XMLRoot.channel.item)>

<!--- Loop through all the items --->
<cfloop index="itms" from="1" to="#Item_Length#">
<!--- Retrieve the current Item in the loop --->
<cfset tmp_Item = XMLRoot.channel.item[itms]>

<!--- Retrieve the item data --->
<cfset grabthis = tmp_Item.grabthis.xmltext>

<!--- Output the items in the browser --->
<cfoutput>
#grabthis#
</cfoutput>
 . </cfloop>
<cfelse>
<!--- If the validation flag is false display error --->
Invalid XML/RSS object!
</cfif>

I'm not really a php guy, but if you need more advice and maybe post the code i will give it a try :)
0
 

Author Comment

by:questhaven
ID: 17861094
Thanks for your help Marco!  In the end I decided to write a parser to grab the data I needed - I  figured that I am not dealing with a huge amount of data anyway, so it just made more sense.  Here is the parser in case anyone else runs into this and wants to see an alternative:

<cfscript>
      onList = "";
      if (findNoCase("<on>", xmlString))
      {
            onList = removeChars(xmlString, 1, findNoCase("<on>", xmlString) + 6);
            onList = replaceNoCase(removeChars(onList, findNoCase("</on>", onList) - 4, len(onList)), "</u><u>", ",", "all");
      }
      
      offList = "";
      if (findNoCase("<off>", xmlString))
      {
            offList = removeChars(xmlString, 1, findNoCase("<off>", xmlString) + 7);
            offList = replaceNoCase(removeChars(offList, findNoCase("</off>", offList) - 5, len(offList)), "</u><u>", ",", "all");
      }
</cfscript>
0
 
LVL 2

Expert Comment

by:Marco_van_den_Oever
ID: 17861552
Hi there:) No problem, great to help and thanks for the example code, it's in my snippets folder now :)
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

721 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