Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spry XML Data Set, choosing specific rows

Status
Not open for further replies.

maguskrool

Technical User
Dec 11, 2006
77
0
0
PT
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:
projects.xml:
<project_list>
   <project name="proj1">
      <title>project one</title>
      <date>2008</date>
      <slogan>project one is great</slogan>
   </project>
   <project name="proj2">
      <title>project two</title>
      <date>2008</date>
      <team>team alpha</team>
      <description>it was something we did</description>
   </project>
</project_list>

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

And then there are the content areas:
Code:
<div id="proj1">
   <p>title goes here</p>
   <div id="gallery">
      (...gallery)
   </div>
   <p>date goes here</p>
   <div id="pub">
      (...banner)
      <p>slogan goes here</p>
   </div>
</div>
<div id="proj2">
   <p>title goes here / date goes here</p>
   <div id="team stuff">
      <p>team goes here</p>
      <div>
         <p>description goes here</p>
      </div>
   </div>
</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:
<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)
</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.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top