473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Searching an XML document with Coldfusion

2
I am trying to retrieve data from my xml file into a coldfusion web service, the xml is valid but when the web service attempts to search the xml it throws back an error - An error occured while Parsing an XML document - not the most useful of errors so I am a bit stumped, here is my web service:

Expand|Select|Wrap|Line Numbers
  1. <cfcomponent>  
  2.  <cffunction name="getDetails"              
  3.    access="remote"              
  4.    returntype="string"              
  5.    output="no" >  
  6.  
  7.  
  8. <cfargument name="inputString" type="string" required="yes">  
  9.  
  10.  
  11.     <cfset xmlFileAddress = Expandpath("XMLcoursework.xml")>
  12.     <cffile action="READ" file="#xmlFileAddress#" variable="xmlObject">
  13.     <cfset xmlDOM = "XMLParse(#xmlObject#)">
  14.  
  15.     <cfset scoreEXP = "/MiniLeagueTeams/MATCHES/match[@name='inputString']/score">
  16.     <cfset score = XmlSearch(xmlDOM, scoreEXP)>
  17.  
  18.  
  19.    <cfset returnval = "test">
  20.  
  21.    <cfreturn returnval>  
  22.  </cffunction>
  23. </cfcomponent>
And here is my xml (cut down version):

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <MiniLeagueTeams xmlns="w3" xsi:schemaLocation="w3 file:///C:/ColdFusion8/wwwroot/SCHEMAcoursework.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  3.  
  4. <TEAMS>
  5.     <team id="1">
  6.         <teamName>Chelsea</teamName>
  7.         <gamesPlayed>6</gamesPlayed>
  8.         <won>1</won>
  9.         <drawn>1</drawn>
  10.         <lost>0</lost>
  11.         <gf>1</gf>
  12.         <ga>1</ga>
  13.         <GFminusGA>2</GFminusGA>
  14.         <points>722</points>
  15.         <yellowCards>
  16.             <playerName>player1</playerName>
  17.             <playerName>player2</playerName>
  18.         </yellowCards>
  19.         <redCards>
  20.             <playerName>player1</playerName>
  21.         </redCards>
  22.     </team>
  23. </TEAMS>
  24.  
  25. <MATCHES>
  26.          <match name="Chelsea VS Valencia">
  27.                 <home>
  28.                       <teamName>Chelsea</teamName>
  29.                       <goals>
  30.                              <goalScorer>Player1</goalScorer>
  31.                       </goals>
  32.                 </home>
  33.                 <away>
  34.                       <teamName>Valencia</teamName>
  35.                       <goals>
  36.                              <goalScorer>Player2</goalScorer>
  37.                              <goalScorer>Player3</goalScorer>
  38.                       </goals>
  39.                 </away>
  40.                 <score>2 - 1</score>
  41.                 <winner>Valencia</winner>
  42.          </match>
  43. </MATCHES>
  44.  
  45. </MiniLeagueTeams>
I able to retrieve data from the xml file using coldfusion functions like this:

Expand|Select|Wrap|Line Numbers
  1. <cfset xmlFile = Expandpath("XMLcoursework.xml")>
  2. <cffile action="READ" file="#xmlFile#" variable ="xmlObject">
  3. <cfset xmlDOM = XMLParse(xmlObject)>
  4.  
  5. <cfset noMatches = ArrayLen(xmlDOM.XMLROOT.XMLChildren[2].XmlChildren)>
  6.  
  7. <cfloop from="1" to="#noMatches#" index="i">
  8.  
  9.     <cfset currentMatch = xmlDOM.XMLRoot.XmlChildren[2].XmlChildren[i]>
  10.     <cfset matchName = currentMatch.XmlAttributes.name>    
  11.  
  12.     <cfif #matchName# EQ "Chelsea VS Valencia">
  13.         <cfset score= currentMatch["score"].XmlText>
  14.         <cfdump var="#score#"/>
  15.     </cfif>
  16.  
  17. </cfloop>
but when i try use this code in the web service it doesn't work either, I'm really not sure what to do next, I am quite new to this so I must be misunderstandinng something, any suggestions would be much appreciated
Dec 20 '07 #1
1 1785
Dököll
2,364 Expert 2GB
Sending over to Coldfusion on your behalf.

Hope you find what you're looking for:-)

Have a Great New Year!!!
Dec 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

60
by: English Teacher | last post by:
Which would be more useful to learn, PHP or COLDFUSION? I know Coldfusion is popular in the work force. Is PHP? Thanks!
16
by: worzel | last post by:
is python more popular than coldfusion? I realsie that is a very general question as one thing does not directly relate to the other. My issue is that I am ditching coldfusion due to there being...
5
by: Steve G | last post by:
Steve G Feb 1, 1:12 pm show options From: "Steve G" <sgr...@computicle.com> - Find messages by this author Date: Tue, 01 Feb 2005 13:12:42 -0800 Local: Tues, Feb 1 2005 1:12 pm Subject:...
4
by: William Fields | last post by:
Hello, I'm trying to find out more information about ColdFusion and could not find what I'm looking for on Macromedia's website. My question has more to do with what ColdFusion is and how web...
0
acoder
by: acoder | last post by:
This page will link to a number of tutorials. Coldfusion Language Coldfusion Variables Using Coldfusion Variables Coldfusion Image Gallery How to upload a file in Coldfusion Watch this...
3
acoder
by: acoder | last post by:
How to Upload a File in Coldfusion Use the cffile tag for uploading files to the server. Note that allowing people to upload files is fraught with danger and only trusted users should be...
7
acoder
by: acoder | last post by:
This page will link to a number of tutorials. Coldfusion Language Coldfusion Variables Using Coldfusion Variables Coldfusion Image Gallery How to upload a file in Coldfusion How to send...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
106
by: bonneylake | last post by:
Hey Everyone, Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.