Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BlakTornado

Guest
Original poster
Apr 24, 2007
944
0
Washington, OH
I'm looking for help into making a dynamic XML parser.

I have a reasonably good knowledge of XML; after all, it's pretty flexible.

Basically, I've got a website that showcases a variety of my own animations, videos, music and podcasts, but the thing is that I have well over 60 or so different items. I recently had a server change which messed a load of things up because I recently switched to Mac around the same time, so I didn't have most of the files I needed. To cut a long story short, I basically redesigned my website.

For reference, this is the URL: http://www.blaktornado.com

Anyway, from what I've read on the web, I can basically create an XML file with all the information I need in it and somehow parse it?

Well the actual parsing bit isn't hard, really. I know roughly how to do that.

But I don't know how to dynamically parse it?

If I had my XML feed like this: (with all the XML meta bits at the top)

Code:
<video>
<title>Video 1</title>
<subtitle>This is a video</subtitle>
<icon>http://example.com/icon1.png</icon>
</video>
<video>
<title>Video 2</title>
<subtitle>This is another video</subtitle>
<icon>http://example.com/icon2.png</icon>
</video>

How would I add an ID to this so that each one could be individually loaded upon request?
Should I add a tag like
Code:
<id>THIS ID</id>

or should I include the ID like this:

Code:
<video id="Video ID">

And how would I then dynamically load it in the dynamic parser?
I can only make a static parser at the moment (Albeit a buggy parser, a parser non-the-less).

Preferably I would like the user to click a link to something like this:

http://www.blaktornado.com/player.html?id=482

(or whatever)

to get to one movie and then

http://www.blaktornado.com/player.html?id=348

to get to a different one.

Any help appreciated. This may be too complex for someone to explain but all and any help would be appreciated. Thanks in advance :)

and please ask if you don't get what I'm asking. I'll happily explain. I'm not fluent with my web design terminology; it's only a hobby.
 
I use PHP and XSLT to parse and handle XML and change it into a web page. For instance on my site I have a recipe section split up into categories. All of my recipes are in a single XML file and there's multiple categories that are associated with each. I then send a parameter from PHP to my XSL for the transformation and so I can just pull out a certain category of recipes which will then be displayed on a page.

Here's part of my PHP
PHP:
  $xsl = new DomDocument();
  $xsl->load("recipe_xsl.xsl");
  $inputdom = new DomDocument();
  $inputdom->load("recipes.xml");
   /* create the processor and import the stylesheet */
  $proc = new XsltProcessor();
  $xsl = $proc->importStylesheet($xsl);
  $proc->setParameter(null, "category", "japanese");
   /* transform and output the xml document */
  $newdom = $proc->transformToXml($inputdom);
  echo $newdom;
The "$proc->setParameter" line is where I set the parameter (in this case category is set to japanese) for the XSL, which you can pull out of the URL or from the $_POST variable.

Then in my XSL file I receive the parameter,
Code:
<xsl:param name="category" select="" />
The parameter will actually be set during the transformation so doesn't need to be set unless you want a default value. Then you can do a search in the XSL based on that parameter,
Code:
<xsl:for-each select="recipe[@cat=$category]">
This is from my own stuff so won't directly give you what you need, but may set you in the right direction.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.