frankfrank
21 Dec 2010, 05:31 AM
Hey.
I have been trying to learn how to pull data from an XML file into a spry widget (accordion in this case) and it just does not seem to work for me.
My practice subject is a TV show and what I want it to do is display the season in the "AccordionPanelTab" and repeat the episode number and title in the "AccordionPanelContent". I also want the "AccordionPanelTab" to repeat when a new season number is added. (Is that possible)? Here is a diagram I made to help explain:
http://img844.imageshack.us/img844/9527/spry.gif
Here is my code:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="/SpryAssets/xpath.js" type="text/javascript"></script>
<script src="/SpryAssets/SpryData.js" type="text/javascript"></script>
<script src="SpryAssets/SpryAccordion.js" type="text/javascript"></script>
<script type="text/javascript">
var dsTvShow = new Spry.Data.XMLDataSet ("mentalist.xml", "tvShow/show");
</script>
<link href="SpryAssests/SpryAccordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="accWrap">
<div id="Accordion1" class="Accordion" tabindex="0" spry:region="dsTvShow">
<div class="AccordionPanel">
<div class="AccordionPanelTab" spry:repeat="dsTvShow">{season}</div>
<div class="AccordionPanelContent" spry:repeat="dsTvShow">{ep}-{title}</div>
</div>
</div>
</div>
<script type="text/javascript">
<!--
var Accordion1 = new Spry.Widget.Accordion("Accordion1");
//-->
</script>
</body>
</html>
XML:
<?xml version="1.0" encoding="utf-8"?>
<tvShow>
<show name="The Mentalist" season="Season 1" index="0">
<season>1</season>
<ep>1</ep>
<title>Pilot</title>
<date>12/03/91</date>
<desc><![CDATA[California Bureau of Investigation consultant Thomas Jane along with Senior Agent Teresa Lisbon and her team, investigate a double murder in which a pro golfer's wife and her doctor were killed in Palm Springs.']]></desc>
</show>
<show name="The Mentalist" season="Season 1" index="1">
<ep>2</ep>
<title>Red Hair and Silver Tape</title>
<date>21/03/91</date>
<desc><![CDATA[Lisbon and the team investigate the death of a waitress in Napa Valley as Patrick decides to take matters into his own hands by going undercover.]]></desc>
</show>
</tvShow>
And here is the result... http://xmlspryhelp.net23.net/
I hope someone can help me out :)
Thanks!
-Frank
I have been trying to learn how to pull data from an XML file into a spry widget (accordion in this case) and it just does not seem to work for me.
My practice subject is a TV show and what I want it to do is display the season in the "AccordionPanelTab" and repeat the episode number and title in the "AccordionPanelContent". I also want the "AccordionPanelTab" to repeat when a new season number is added. (Is that possible)? Here is a diagram I made to help explain:
http://img844.imageshack.us/img844/9527/spry.gif
Here is my code:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="/SpryAssets/xpath.js" type="text/javascript"></script>
<script src="/SpryAssets/SpryData.js" type="text/javascript"></script>
<script src="SpryAssets/SpryAccordion.js" type="text/javascript"></script>
<script type="text/javascript">
var dsTvShow = new Spry.Data.XMLDataSet ("mentalist.xml", "tvShow/show");
</script>
<link href="SpryAssests/SpryAccordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="accWrap">
<div id="Accordion1" class="Accordion" tabindex="0" spry:region="dsTvShow">
<div class="AccordionPanel">
<div class="AccordionPanelTab" spry:repeat="dsTvShow">{season}</div>
<div class="AccordionPanelContent" spry:repeat="dsTvShow">{ep}-{title}</div>
</div>
</div>
</div>
<script type="text/javascript">
<!--
var Accordion1 = new Spry.Widget.Accordion("Accordion1");
//-->
</script>
</body>
</html>
XML:
<?xml version="1.0" encoding="utf-8"?>
<tvShow>
<show name="The Mentalist" season="Season 1" index="0">
<season>1</season>
<ep>1</ep>
<title>Pilot</title>
<date>12/03/91</date>
<desc><![CDATA[California Bureau of Investigation consultant Thomas Jane along with Senior Agent Teresa Lisbon and her team, investigate a double murder in which a pro golfer's wife and her doctor were killed in Palm Springs.']]></desc>
</show>
<show name="The Mentalist" season="Season 1" index="1">
<ep>2</ep>
<title>Red Hair and Silver Tape</title>
<date>21/03/91</date>
<desc><![CDATA[Lisbon and the team investigate the death of a waitress in Napa Valley as Patrick decides to take matters into his own hands by going undercover.]]></desc>
</show>
</tvShow>
And here is the result... http://xmlspryhelp.net23.net/
I hope someone can help me out :)
Thanks!
-Frank