The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
XML page cannot be displayed
Discuss XML page cannot be displayed in the ColdFusion Development forum on Dev Shed. XML page cannot be displayed ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 26th, 2011, 07:28 AM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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?
|

August 26th, 2011, 08:47 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
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/
|

August 29th, 2011, 07:30 AM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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.
|

August 29th, 2011, 09:21 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
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.
|

August 29th, 2011, 09:39 AM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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?
|

August 29th, 2011, 12:33 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
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.
|

August 30th, 2011, 10:34 AM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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>
|

August 30th, 2011, 03:05 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
You're setting this to "producers" but you're referencing it later as "producer".
|

August 30th, 2011, 03:53 PM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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>
|

August 30th, 2011, 07:54 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
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.
|

August 31st, 2011, 04:33 AM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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>
|

August 31st, 2011, 09:56 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
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.
|

August 31st, 2011, 11:34 AM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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?
|

August 31st, 2011, 01:21 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
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 01:25 PM.
|

September 3rd, 2011, 07:12 PM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 31
Time spent in forums: 3 h 50 m 17 sec
Reputation Power: 2
|
|
|
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?
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|