Searching an XML document with Coldfusion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Morag
    New Member
    • Dec 2007
    • 2

    Searching an XML document with Coldfusion

    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:

    [CODE=VB]<cfcomponent>
    <cffunction name="getDetail s"
    access="remote"
    returntype="str ing"
    output="no" >


    <cfargument name="inputStri ng" type="string" required="yes">


    <cfset xmlFileAddress = Expandpath("XML coursework.xml" )>
    <cffile action="READ" file="#xmlFileA ddress#" variable="xmlOb ject">
    <cfset xmlDOM = "XMLParse(#xmlO bject#)">

    <cfset scoreEXP = "/MiniLeagueTeams/MATCHES/match[@name='inputStr ing']/score">
    <cfset score = XmlSearch(xmlDO M, scoreEXP)>


    <cfset returnval = "test">

    <cfreturn returnval>
    </cffunction>
    </cfcomponent>[/CODE]

    And here is my xml (cut down version):

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <MiniLeagueTeams xmlns="w3" xsi:schemaLocation="w3 file:///C:/ColdFusion8/wwwroot/SCHEMAcoursework.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
    <TEAMS>
        <team id="1">
    		<teamName>Chelsea</teamName>
    		<gamesPlayed>6</gamesPlayed>
    		<won>1</won>
    		<drawn>1</drawn>
    		<lost>0</lost>
    		<gf>1</gf>
    		<ga>1</ga>
    		<GFminusGA>2</GFminusGA>
    		<points>722</points>
    		<yellowCards>
    			<playerName>player1</playerName>
    			<playerName>player2</playerName>
    		</yellowCards>
    		<redCards>
    			<playerName>player1</playerName>
    		</redCards>
    	</team>
    </TEAMS>
    
    <MATCHES>
             <match name="Chelsea VS Valencia">
                    <home>
                          <teamName>Chelsea</teamName>
                          <goals>
                                 <goalScorer>Player1</goalScorer>
                          </goals>
                    </home>
                    <away>
                          <teamName>Valencia</teamName>
                          <goals>
                                 <goalScorer>Player2</goalScorer>
                                 <goalScorer>Player3</goalScorer>
                          </goals>
                    </away>
                    <score>2 - 1</score>
                    <winner>Valencia</winner>
             </match>
    </MATCHES>
    	
    </MiniLeagueTeams>
    I able to retrieve data from the xml file using coldfusion functions like this:

    [CODE=VB]<cfset xmlFile = Expandpath("XML coursework.xml" )>
    <cffile action="READ" file="#xmlFile# " variable ="xmlObject" >
    <cfset xmlDOM = XMLParse(xmlObj ect)>

    <cfset noMatches = ArrayLen(xmlDOM .XMLROOT.XMLChi ldren[2].XmlChildren)>

    <cfloop from="1" to="#noMatches# " index="i">

    <cfset currentMatch = xmlDOM.XMLRoot. XmlChildren[2].XmlChildren[i]>
    <cfset matchName = currentMatch.Xm lAttributes.nam e>

    <cfif #matchName# EQ "Chelsea VS Valencia">
    <cfset score= currentMatch["score"].XmlText>
    <cfdump var="#score#"/>
    </cfif>

    </cfloop>[/CODE]

    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 misunderstandin ng something, any suggestions would be much appreciated
    Last edited by Dököll; Dec 28 '07, 02:34 AM. Reason: HTML/VB Code tags
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Sending over to Coldfusion on your behalf.

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

    Have a Great New Year!!!
    Last edited by Dököll; Dec 28 '07, 02:37 AM. Reason: text deleted...

    Comment

    Working...