Local XML file and datasources - error

sstava 8 years ago updated by icahill (Administrator) 8 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:

<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" />



<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"/>

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

XML file content:

<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<title>The Economist: The world this week</title>
<description>The world this week</description>
<lastBuildDate>Thu, 16 August 2012 15:04:05 GMT</lastBuildDate>
<title>Business this week</title>
<pubDate>Thu, 16 August 2012 15:04:05 GMT</pubDate>
<title>Politics this week</title>
<pubDate>Thu, 16 August 2012 15:04:05 GMT</pubDate>
<title>KAL&#039;s cartoon</title>
<pubDate>Thu, 16 August 2012 15:04:05 GMT</pubDate>

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.