Page 1 of 4 123 ... Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4

    XML page cannot be displayed


    Well let me start of by saying im at the beginners level as a devleoper. My 1st task was to create an XML using coldfusion.

    I started by writing it in notepad using the here is code below.


    <?xml version="1.0" encoding="UTF-8"?>




    <cfset xmlAmp = XmlNew() />



    <cfset xmlRoot = XmlElemNew( xmlAmp, "", "man" ) />

    <cfset xmlAmp.xmlRoot = xmlRoot />

    <cfset xmlPersonality = XmlElemNew( xmlAmp, "", "Personality" ) />

    <cfset ArrayAppend( xmlRoot.XmlChildren, xmlPersonality ) />

    <cfset xmlspiritenergy = xmlElemNew( xmlAmp, "", "spiritenergy" ) />

    <cfset ArrayAppend( xmlRoot.XmlChildren, Xmlspiritenergy ) />







    <cfset xmlRoot.Personality.xmlAttributes.Fun = true />
    <cfset xmlRoot.Personality.xmlAttributes.Happy = true />
    <cfset xmlRoot.Personality.xmlAttributes.Nice = true />
    <cfset xmlRoot.Personality.XmlAttributes.Generous = false />
    <cfset xmlRoot.Personality.XmlAttributes.Evil = false />

    <cfset xmlRoot.spiritenergy.xmlAttributes.Range = "3000km" />
    <cfset xmlRoot.spiritenergy.xmlAttributes.Color = "Blue" />
    <cfset xmlRoot.spiritenergy.xmlAttributes.Definition = "Good" />
    <cfset xmlRoot.spiritenergy.xmlAttributes.Age = "30" />
    <cfset xmlRoot.spiritenergy.xmlAttributes.Status = "Working" />

    <cfdump
    var="#xmlAmp#"
    label="xmlAmp XML DOM" />



    When i goto to display it under localhost:8500/"".xml I get an error message "A string literal was expected, but no opening quote character was found. Error processing resource 'http://localhost:8500/a...

    <cfset xmlAmp = XmlNew() />

    Was I suppose to include xmlAmp in the brackets?
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    No, it is probably the XML tag you have at the top of your page. You don't need that.

    Also, you may be doing this the hard way, because you could just create the string and then parse it into XML, something like this: http://tutorial18.learncf.com/
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4
    Hey thanks, now that I have this part done. Do I have to create a .cfm file to refer to this xml?

    Im going to refer to the example you led me to above. I want to create a page that would allow me to search an artist or a title from a webpage.
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    I'm not sure what you mean. At this point there is no XML file...you're creating it within the CF request. If you want to save it to disk, you'd need to use CFFILE to write it to the drive.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4
    Well its like this, by the example given. I created the xml it contains my information title, aurthor, and isbn#.

    To view the xml in a webpage do i just goto my browser and type http://localhost:8500/"".xml?
  10. #6
  11. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    If you're building up the XML using cfsavecontent, no. The XML is only in-memory and only exists for the duration of that request. If you want to write the XML to a file on disk, you must use cffile after you create the XML object.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4
    Ok i was able to see what you were talking about. But I do have one question what could possibly be wrong with this line.

    I keep returning the message of no variable set for producer


    <cfsavecontent variable="amp2.xml"><?xml version="1.0"?>

    <cfset Producers = xmlSearch(amp2.xml, 'Movies/Anime/title/producer')>
    <cfoutput>

    <h2>Producer Nodes</h2>
    <cfloop from="1" to="#arraylen(producer)#" index="i">

    <cfset producerXML = xmlparse(producer[i]) />
    <b>Producer:</b> #ProducerXML.producer.xmlText#<br><br>
    </cfloop>
    </cfoutput>
  14. #8
  15. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    You're setting this to "producers" but you're referencing it later as "producer".
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4
    Thanks for pointing that out. I went to create a search button and i was successful with doing that.


    But I want it return with a title from that xml. Would I be using a cfquery against the xml?

    <cfset Animenodes = xmlSearch(amp2.xml, '/Movies/Anime')>
    <cfoutput>
    <h2>Anime Nodes</h2>
    <cfform>
    <div>
    <b>title</b>
    Title
    <cfinput type="text" name="title">
    <cfinput type="submit" name="submitButton" value="Search">
    </div>
    </cfform>
    </cfoutput>
  18. #10
  19. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    cfquery has nothing to do with XML. You can just dump the data to see what its structure is by doing:

    <cfset Animenodes = xmlSearch(amp2.xml, '/Movies/Anime') />
    <cfdump var="#Animenodes#" />

    Also, have you looked at the documentation on using XML with CF? It has full sections on creating XML and using XPath.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4
    Ok i was able to dump the context of the XML out into a grid and I was able to do the different displaying of informatio using the tutorial.

    But instead of dumping the information from the xml I wanted to make a search button for an end user to search the title or producer.

    So far I got stuck here and I can get the searh button to display but I'm not sure how to get it to return with a title.


    cfsavecontent variable="amp2.xml"><?xml version="1.0"?>

    <Movies>

    <Anime>
    <title>Ties To Darkness</title>
    <producer>Nicole Long</producer>
    </Anime>
    <Anime>
    <title>Misty Fog</title>
    <producer>Chris West</producer>
    </Anime>

    <Anime>
    <title>Spirit of Echos</title>
    <producer>Amp</producer>
    </Anime>
    </Movies>
    </cfsavecontent>


    <cfset amp2.xml = xmlParse (amp2.xml) />




    <cfset Animenodes = xmlSearch(amp2.xml, '/Movies/Anime')>
    <cfoutput>
    <h2>Anime Nodes</h2>
    <cfform>
    <div>
    <b>title</b>
    Title
    <cfinput type="text" name="title">
    <cfinput type="submit" name="submitButton" value="Search">
    </div>
    </cfform>
    <cfset amp2.xml = XMLParse(amp2.xml)>

    <cfloop index="i" from="1" to ="#Arraylen(Anime)#">
    <cfset AnimeXML = xmlparse(Anime[i])/>

    <cfset Title = XMLSearch (amp2.xml,"/Movies/Anime/Title*[amp2.xml(title)='item'][#i#]/*[amp2.xml(title)='title']")>
    <cfset title = title[1].xmltext>
    </cfloop>
    </cfoutput>
  22. #12
  23. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    XML isn't really a very robust mechanism for searching data, it is a storage and transport format. So you can use XPath to perform your searches against the XML if you want to, but it will get increasingly complex as the number of things you want to search for increases.

    If the actual XML is going to contain more than a few sample nodes, you probably want to parse the XML and insert it into a database as actual relational data, and then search the database.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4
    I didn't plan making it more bigger then just these few sample nodes.


    But just for testing purposes where would I plug in my Xpath code to allow an end user inputdata to get Movies?
  26. #14
  27. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    On whatever page the form submits to. Right now you don't have a form action attribute defined, so by default it submits back to the same page.

    You should also be able to do something like:

    Code:
    <cfsavecontent variable="amp2.xml"><?xml version="1.0"?>
    <Movies>
    <Anime>
    <title>Ties To Darkness</title>
    <producer>Nicole Long</producer>
    </Anime>
    <Anime>
    <title>Misty Fog</title>
    <producer>Chris West</producer>
    </Anime>
    <Anime>
    <title>Spirit of Echos</title>
    <producer>Amp</producer>
    </Anime>
    </Movies>
    </cfsavecontent>
    
    <cfset amp2.xml = xmlParse( amp2.xml ) />
    
    <cfoutput>
    	
    <cfif StructKeyExists( form, 'title' )>
    
    	<!--- Do XPath search based on form.title --->
    
    <cfelse>	
    
    	<h2>Anime Nodes</h2>
    	<cfform>
    	<div>
    	<b>title</b>
    	Title
    	<cfinput type="text" name="title">
    	<cfinput type="submit" name="submitButton" value="Search">
    	</div>
    	</cfform>
    
    </cfif>
    Last edited by kiteless; August 31st, 2011 at 02:25 PM.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    31
    Rep Power
    4
    Ok you kind of lost me there.

    I need plug in an Xpath search feature outside of the cfform?

    Also how is the variable defined for <cfif StructKeyExists?
Page 1 of 4 123 ... Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo