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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML help: adding a new attribute

Status
Not open for further replies.

digitalpencil

Programmer
Apr 8, 2001
165
GB
Hi,
I've been using the videosource tutorial as a guide for creating a dynamic FLV gallery which loads (from an XML file) the paths to some thumbnail jpgs and some itemnames for assembly in a list component. The paths to the FLVs are also loaded from here.
This is working fine, (although needs significant tarting up) but now I would like to add a description box which is also referenced from the XML file. I've tried everything I can think of but I've never been great with it and I just can't figure out where I'm messing it up..

A simplified version of my xml is:
Code:
<xml> 
   <listitem name="Video Title" url="[URL unfurl="true"]http://www.url.com/FLVs/"[/URL] thumb="1.jpg"> 
   <stream name="1.FLV" start="0" len="-1"/> 
   </listitem> 
<menu> 
   <listitem name="Video Title"/> 
</menu> 
<description> 
   <info="video description"/> 
</description> 
</xml>


and the code that then loads the XML and assembles the content in the list component is:

Code:
//-------------------------LIST SELECTION CHANGE----------------------------- 
//Add an event listener on the list, when it triggers, run the listListener function to repopulate the list 
list.addEventListener("change", listListener); 


//Function that loads the XML file, parses it, and builds the list of available video clips 
   var xmllist = new XML();        //setup a variable to hold the XML 
   xmllist.ignoreWhite = true; 
   xmllist.load( "video_playlist.xml" );    //load the XML file 
   //The following gets called when the XML has been loaded 
   xmllist.onLoad = function( status )  { 
      if ( !status ) 
         trace( status ); 
      var entries = this.childNodes[0]; 
      var playlists = {}; 
      var nav = []; 
      var descrip = {}; 
      var infopanel = []; 
      for ( var i = 0; i < entries.childNodes.length; i++ ) { 
         var entry = entries.childNodes[i]; 
         if ( entry.nodeName == "listitem" ) 
            //builds array of video clip names 
            playlists[entry.attributes.name] = entry; 
             
         else if ( entry.nodeName == "menu" ) { 
            //builds array of available videos 
            for ( var j = 0; j < entry.childNodes.length; j++ ) 
            nav[j] = playlists[entry.childNodes[j].attributes.name]; 
             
         if ( entry.nodeName == "description" ) { 
            //builds array of available descriptions 
            infopanel = descrip[entry.attributes.info] = entry; 
         } 
             
         } //end else if 
      } //end if 

      //sends the array of videos to the listbox UI 
      list.dataProvider = nav; 
      _root.description.text = infopanel; 
   } //end xmllist.onload


All I really want to do is load the descriptions from the xml into a dynamic text field on the main stage instance named 'description'..
I've been trying this for ages now and am feeling pretty dumb 'cause I just can't figure it out.
I'd be really grateful if anyone could spare a moment to take a look and see if they can work out where i'm going wrong here.

If it helps, I've uploaded my files to the following:
(open directory containing all files)
(or, one big zip with everything on it for convenience)

Thanks for reading.
 
Hmm.. i'm quite willing to search through here but a little more info on how it's not proper XML would be much appreciated. As that really just confused me further..
I've since realised that 'info' wasn't an attribute but was a childnode and so have changed that in the XML (or whatever it may be*) to: <description info="a description"/>
That hasn't helped any..

I've tried re-rwiting this as it's code I've lifted from a tutorial. Managed to get the description panel working with it but then the list is crippled.
I think this might be because it's talking to some code in a seperate AS file (thumb.as) involving the cellrenderer class which, i've never played with before.
Any light you can shed is much appreciated,
Thanks for the reply,
Dave
 
A quick test is to open your XML in Firefox etc. It'll complain if your XML is not valid.

If I were you I'd structure the XML something like this:

<?xml version="1.0" ?>
<playlist>
<video name="Video title 1">
<url> <thumb>1.jpg</thumb>
<stream>1.FLV</stream>
<start>0</start>
<len>-1</len>
<description>Some descriptions for video 1</description>
</video>
<video name="Video title 2">
<url> <thumb>2.jpg</thumb>
<stream>2.FLV</stream>
<start>0</start>
<len>-1</len>
<description>Some descriptions for video 2</description>
</video>
... more videos
</playlist>

Kenneth Kawamoto
 
Ahh.. that's a good trick (*mental note*).
Cool, so... structured with nodes and childnodes, and no attributes (that'll let me wrap CDATA around the descriptions later come to think of it).
Right, will give that a whirl tonight and see how I get on.

Thanks a lot for your help,
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top