Spry xml data set, accessing specific rows

  • maguskrool
  • Born
  • Born
  • maguskrool
  • Posts: 3

Post 3+ Months Ago

Hello. I've been trying to build a website using Spry XML Data Sets, and while I've accomplished my goals for now, I don't think the solution I came up with is the best.

The website consists of several areas that show projects. Each project has several fields that are to be filled with content retrieved from the xml files, but the projects are not all exactly alike and some have specific fields that others don't require.

All the info is available in several languages, so for now I've created an xml file for each one. Here's what an xml file could be like:
Code: [ Select ]
   <project name="proj1">
      <title>project one</title>
      <slogan>project one is great</slogan>
   <project name="proj2">
      <title>project two</title>
      <team>team alpha</team>
      <description>it was something we did</description>
  2. projects.xml:
  3. <project_list>
  4.    <project name="proj1">
  5.       <title>project one</title>
  6.       <date>2008</date>
  7.       <slogan>project one is great</slogan>
  8.    </project>
  9.    <project name="proj2">
  10.       <title>project two</title>
  11.       <date>2008</date>
  12.       <team>team alpha</team>
  13.       <description>it was something we did</description>
  14.    </project>
  15. </project_list>

This dataset, for simplicity purposes, is not dependent on the language:
Code: [ Select ]
var dsProjects = new Spry.Data.XMLDataSet("projects.xml", "project_list/project");
  2. var dsProjects = new Spry.Data.XMLDataSet("projects.xml", "project_list/project");

And then there are the content areas:
Code: [ Select ]
<div id="proj1">
   <p>title goes here</p>
   <div id="gallery">
   <p>date goes here</p>
   <div id="pub">
      <p>slogan goes here</p>
<div id="proj2">
   <p>title goes here / date goes here</p>
   <div id="team stuff">
      <p>team goes here</p>
         <p>description goes here</p>
  2. <div id="proj1">
  3.    <p>title goes here</p>
  4.    <div id="gallery">
  5.       (...gallery)
  6.    </div>
  7.    <p>date goes here</p>
  8.    <div id="pub">
  9.       (...banner)
  10.       <p>slogan goes here</p>
  11.    </div>
  12. </div>
  13. <div id="proj2">
  14.    <p>title goes here / date goes here</p>
  15.    <div id="team stuff">
  16.       <p>team goes here</p>
  17.       <div>
  18.          <p>description goes here</p>
  19.       </div>
  20.    </div>
  21. </div>

So as you see, each project has its own structure. This makes using spry:repeat a not very effective method for filling in all the content. Ideally I should be able to access each row in the dataset through some sort of value, like id, or one of its children's values. The ds_RowID depends on the row order, so unless there's another way to use it, it doesn't solve my problem.

Here's what I've come up with:
Code: [ Select ]
<div id="proj1" spry:region="dsProjects" spry:repeat="dsProjects">
   <p spry:if="'{@id}'=='proj1'">{title}</p>
   (same method for each other element I need to retrieve from the xml dataset)
  2. <div id="proj1" spry:region="dsProjects" spry:repeat="dsProjects">
  3.    <p spry:if="'{@id}'=='proj1'">{title}</p>
  4.    (same method for each other element I need to retrieve from the xml dataset)
  5. </div>

This works (in FF3 OSX, at least), although there are some other problems that might make it necessary to create a spry:region (or at least use spry:repeat) for each field. Anyway, it sounds silly and wasteful to go through every row of the dataset everytime for each of the fields that need to be filled.

My hope is that I'm ignorant of some much better method of achieving my goals, something more direct and elegant.

Can anyone help me out with this? Thank you very much in advance.

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.