+1
Answered

Local XML file and datasources - error

sstava 12 years ago updated by icahill (Administrator) 12 years ago 1
I am trying to do something simple...so I thought. In reality, I may be simple and that could be the problem :) so any help would be greatly appreciated!

My goal was to have a local XML file and display the contents in my app. I was basing the code off of the rssfeed example in the intro to data sources tutorial. The rssfeed app works fine for me...Yay!

So, back to my original goal...displaying the content of an app-local XML file.
When I use a data source to load the XML file, I get a data source error. That is obviously what prevents me from showing the data, but I can't figure out what is causing the error or what the specific error is.

I have copied an rss feed's XML content into my local xml file to make sure the XML file is valid. In my example app, I have two data sources.

One is the Internet-based rss feed...it works.

The other is the same rss content, but copied into an app-local XML file...it fails.

My example app:




<wire>
<datasources>
<datasource name="economistrss" source="http://www.economist.com/rss/the_world_this_week_rss.xml" providertype="xml" query="//item" />
<datasource name="economistxml" source="economist.xml" providertype="xml" query="//item" />
</datasources>

<styles>
</styles>

<classes>
</classes>

<main>
<panel name="canvas" alias="CANVAS" width="100%" height="100%" background="#cc0000">
<text name="info" alias="INFO" text="Before Change" font="helvetica" size="30" color="#cc0000" width="100%" height="25%" alignment="center" align="center" valign="center" background="#ffffff" onclickup="show-rss" onswipedown="show-xml"/>
</panel>
</main>

<actions>
<action name="show-rss" >
<assign property="object:INFO.text" value="[datasource:economistrss.dataSourceResultCount]" />
</action>
<action name="show-xml" >
<assign property="object:INFO.text" value="[datasource:economistxml.dataSourceResultCount]" />
</action>
<action name="error-rss" datasource="economistrss" datasourceevent="datasourceerror">
<assign property="object:INFO.text" value="Economist RSS: datasource error" />
</action>
<action name="error-xml" datasource="economistxml" datasourceevent="datasourceerror">
<assign property="object:INFO.text" value="Economist XML: datasource error" />
</action>
</actions>
</wire>



XML file content:




<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>The Economist: The world this week</title>
<description>The world this week</description>
<link>http://www.economist.com</link>
<image>
<link>http://www.economist.com</link>
<width>125</width>
<title>Economist.com</title>
<url>//media.economist.com/sites/all/themes/econfinal/images/the-economist-logo.gif</url>
<height>34</height>
</image>
<language>en-gb</language>
<lastBuildDate>Thu, 16 August 2012 15:04:05 GMT</lastBuildDate>
<webMaster>webmaster@economist.com</webMaster>
<managingEditor>rondiorio@economist.com</managingEditor>
<ttl>120</ttl>
<docs>http://www.economist.com/rss/</docs>
<item>
<title>Business this week</title>
<link>http://www.economist.com/node/21560609?fsrc=rss|twt</link>
<guid>http://www.economist.com/node/21560609</guid>
<pubDate>Thu, 16 August 2012 15:04:05 GMT</pubDate>
</item>
<item>
<title>Politics this week</title>
<link>http://www.economist.com/node/21560613?fsrc=rss|twt</link>
<guid>http://www.economist.com/node/21560613</guid>
<pubDate>Thu, 16 August 2012 15:04:05 GMT</pubDate>
</item>
<item>
<title>KAL&#039;s cartoon</title>
<link>http://www.economist.com/node/21560619?fsrc=rss|twt</link>
<guid>http://www.economist.com/node/21560619</guid>
<pubDate>Thu, 16 August 2012 15:04:05 GMT</pubDate>
</item>
</channel>
</rss>

I will need to clarify this further in the documentation as it reads a little funny.

All locally used datasources need to contain "res://" as a prefix in order to call. So in your case, it needs to be:


<datasource name="economistxml" source="res://economist.xml" providertype="xml" query="//item" />


Also your xml file needs to be stored at the root for the code above to be valid.