#16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    Well l've been kinda chasing an alt. route with this xml task.

    I got all they way to the portion of page where I was defining

    my search option and it blows up right in my face. Could you

    let me know if I'm tackling it the right way?

    xml file:
    <album>
    <title>Questions, unanswered</title>
    <artist>Steve and the flubberblubs</artist>
    <year>1989</year>
    <tracks>
    <song tracknumber="1" length="4:05">
    <title>What do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:31</lastplayed>
    </song>
    <song tracknumber="2" length="3:45">
    <title>Who do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:35</lastplayed>
    </song>
    <song tracknumber="3" length="5:14">
    <title>When do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:39</lastplayed>
    </song>
    <song tracknumber="4" length="4:19">
    <title>Do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:44</lastplayed>
    </song>
    </tracks>
    </album>


    mycfm:
    <cfhttp url="http://localhost:8500/interviewtest/music.xml">


    <!---<cfdump var="#cfhttp.FileContent#">--->


    <cfset music = xmlparse("#cfhttp.FileContent#")>

    <!---<cfdump var="#music#" label= "xml document object">--->

    <cfset armusic=music.album.tracks.song>

    <!---<cfdump var="#armusic[1].artist.xmltext#" label="armusic">--->
    <cfscript>
    if (isDefined("form.submitbutton"))
    {
    hql = "FROM armusic WHERE 0=0";
    }


    </cfscript>
    <Title>Artist Search</Title>

    <body>

    <cfform>
    <table border ="0">
    <tr>
    <td>Artist Search:

    </td>
    <td><input type="text" name="artist" size="30" </td>

    </tr>
    <tr>
    <td><input type="submit" value="search" name="submitbutton"

    </td>
    </tr>
    </table>
    </cfform>
    <cfif isDefined(armusic)>

    </cfif>
    /body>
  2. #17
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    "Blows up in your face" doesn't provide any information I can use. Do you get an error? You've got to explain what happens, I can't read your mind.

    Beyond that, I have no idea what this is:

    Code:
    if (isDefined("form.submitbutton"))
    {
    hql = "FROM armusic WHERE 0=0";
    }
    I also don't see any XPath in this code. I asked earlier but you didn't answer so I'll try again: have you actually read the CF documentation that covers XML and XPath?
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    Ok sorry the message that I was getting with the code earlier had a problem with the script that i wanted to get working.


    So I ended up going back to using the Xpath function. I was able to create a cfscript using an array that retrieves the title of the songs from the xml. I tested by using a writoutput tag in the script.

    Now my only problem is that I can't seem to get this Search button to return the title. Please see below.


    <cfhttp url="http://localhost:8500/interviewtest/music.xml">

    <cfset music = xmlparse("#cfhttp.FileContent#")>
    <!---<cfdump var="#cfhttp.FileContent#">--->




    <!---<cfdump var="#music#" label= "xml document object">--->

    <cfset armusic=music.album.tracks.song>

    <cfscript>
    if (isDefined("form.submitbutton"));
    music = xmlparse("#cfhttp.FileContent#");
    selectedElements = XmlSearch(music, "/album/tracks/song/title");
    for (i = 1; i LTE Arraylen(selectedElements); i = i + 1)
    writeoutput (selectedElements[i].xmltext & "<br>");


    </cfscript>
    <Title>Artist Search</Title>

    <body>

    <cfform>
    <table border ="0">
    <tr>
    <td>Artist Search:

    </td>
    <td><input type="text" name="artist" size="30" </td>

    </tr>
    <tr>
    <td><input type="submit" value="search" name="submitbutton"

    </td>
    </tr>
    </table>
    </cfform>
    <cfif isDefined("selectedElements")>


    </cfif>
  6. #19
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    How would i match the title?
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    I have created that script using the XMLSearch array. I though that was all that was needed to allow me to search.

    The reason why is because when i use the writeoutput tag in my cfscript it gives me all the titles.
  12. #22
  13. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    That's because you're not using the value they entered into the form, but are just pulling out ALL of the titles.
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    So should I be changing if (isDefined("form.submitbutton"));
    to if(isDefined("form.search"))?
  16. #24
  17. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    No, you're missing the point. If your XPath search doesn't limit what it looks for to the value passed by the user in form.artist, how can you expect it to do anything OTHER than returning all of the artists? You're not filtering anything.
  18. #25
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    ok now i see a little light..... about the filtering do I have to add a filter to my script? and if so what kind of tag would it be?
  20. #26
  21. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
  22. #27
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    ok thanks.......

    Now I another question. I createded a .cfc file and a action cfm file to reference to it. I am plotting to create a grid in the cfm to display my xml files. Which were in previous post

    I also want to be able to delete the data in this grid and add so that it writes back to the xml.

    I think i got it pretty much covered but I get an error when loading my cfm The message states.

    Error invoking CFC "path leading to my cfc file:"The row number 1 is out of bounds.

    I assume that it may have something to do with one of my query's but im not to sure. Also thanks for all your help.


    <cfcomponent name="ArtistDataManager">
    <cffunction name="getArtist" access="remote" output="false" returnFormat="plain">
    <cfhttp url="http://localhost:8500/interviewtest/music.xml">
    <cfset biggie = xmlparse ("#cfhttp.FileContent#")>
    <cfcontent type="text/xml" reset="yes">
    <cfreturn biggie>
    </cffunction>
    <cffunction name="getData" access="remote" output="false">
    <cfargument name="page" required="yes">
    <cfargument name="pageSize" required="yes">
    <cfargument name="sortCol" required="yes">
    <cfargument name="sortDir" required="yes">
    <cfargument name="filter" required="no">
    <cfhttp url="http://localhost:8500/interviewtest/music.xml">
    <cfset biggie = xmlparse ("#cfhttp.FileContent#")>
    <cfset txe = biggie.album.tracks.song>
    <cfset box = arraylen(txe)>
    <cfset myquery = QueryNew("title, artist")>
    <cfloop index="i" from = "1" to = #box#>
    <cfset temp = QuerySetCell (myquery, "artist", #biggie.album.tracks.song[i].artist.xmltext#, #i#)>
    <cfset temp = QuerySetCell (myquery, "title", #biggie.album.tracks.song[i].title.xmltext#, #i#)>
    </cfloop>
    <cfquery name="Search" datasource="myquery">
    select TITLE, ARTIST from SONG
    <cfif isDefined("arguments.filter") AND arguments.filter NEQ "">
    where GENRE = '#arguments.filter#'

    </cfif>
    <cfif arguments.sortCol NEQ "" AND arguments.sortDir NEQ "">
    order by #arguments.sortCol# #arguments.sortDir#
    <cfelse>
    order by TITLE ASC
    </cfif>
    </cfquery>

    <cfreturn QueryConvertForGrid(Search, arguments.page,
    arguments.pageSize)>
    </cffunction>

    <cffunction name="getArttitle" access="remote" output="false">
    <cfargument name="prodname" default="The Song">

    <cfquery name="SongDetails" datasource="myquery">
    select TITLE, ARTIST from SONG
    where TITLE = '#arguments.prodname#'
    </cfquery>
    <cfoutput>
    <cfxml variable="MUSICXML" >
    <album>
    <title>Questions, unanswered</title>
    <artist>Steve and the flubberblubs</artist>
    <year>1989</year>
    <tracks>
    <song tracknumber="1" length="4:05">
    <title>What do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:31</lastplayed>
    </song>
    <song tracknumber="2" length="3:45">
    <title>Who do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:35</lastplayed>
    </song>
    <song tracknumber="3" length="5:14">
    <title>When do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:39</lastplayed>
    </song>
    <song tracknumber="4" length="4:19">
    <title>Do you know?</title>
    <artist>Steve and the flubberblubs</artist>
    <lastplayed>2006-10-17-08:44</lastplayed>
    </song>
    </tracks>
    </album>
    </cfxml>
    </cfoutput>
    <!--- Convert the XML object to an XML string. --->
    <cfset xmldata = xmlparse(musicxml)>
    <cfcontent type="text/xml" reset="yes">
    <cfreturn xmldata>
    </cffunction>

    </cfcomponent>
  24. #28
  25. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,263
    Rep Power
    968
    You're showing the CFC, not the code that is calling the CFC. The error should have a file and line number where the error is happening.
  26. #29
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    The error message state the following:
    Error invoking CFC/ColdfusionProject/artistdatamanager.cfc: The row number 1 is out of bounds.[Enable debugging by addming'cfdebug to our URL parameters to see more information]
  28. #30
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    3
    Getting this message when i try to put up my cfm code to the forum.


    Could not find phrase 'akismetspam'.

IMN logo majestic logo threadwatch logo seochat tools logo