Dynamic XML parser?

Discussion in 'Web Design and Development' started by BlakTornado, May 7, 2008.

  1. BlakTornado Guest


    Apr 24, 2007
    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)

    <title>Video 1</title>
    <subtitle>This is a video</subtitle>
    <title>Video 2</title>
    <subtitle>This is another video</subtitle>
    How would I add an ID to this so that each one could be individually loaded upon request?
    Should I add a tag like
    <id>THIS ID</id>
    or should I include the ID like this:

    <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:


    (or whatever)

    to get to one movie and then


    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.
  2. angelwatt Moderator emeritus


    Aug 16, 2005
    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
      $xsl = new DomDocument();
    $inputdom = new DomDocument();
    /* create the processor and import the stylesheet */
    $proc = new XsltProcessor();
    $xsl $proc->importStylesheet($xsl);
    /* transform and output the xml document */
    $newdom $proc->transformToXml($inputdom);
    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,
    <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,
    <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.

Share This Page