Hi All:

I have a challenging jQuery XML task I'm trying to accomplish as follows:

I have an XML structure as follows:

<nav_data>
    <outline>
        <links>
            <slidelink slideid="_player.6LjVRsWzPla" displaytext="Scene 1" expand="true">
                <links>
                    <slidelink slideid="_player.6LjVRsWzPla.6GWiXuWmXyn" displaytext="Fundamentals" expand="true" />
                    <slidelink slideid="_player.6LjVRsWzPla.6gxk7XqbaT8" displaytext="Closed Captioning Example" expand="true" />
                    <slidelink slideid="_player.6LjVRsWzPla.5rPNkwvz8u2" displaytext="Another Cationing Example" expand="true" />
                </links>
            </slidelink>
            <slidelink slideid="_player.5vBpwlDk0Kc" displaytext="Scene 2" expand="true">
                <links>
                    <slidelink slideid="_player.5vBpwlDk0Kc.6GFHxzyjyh5" displaytext="Change in Scene" expand="true" />
                    <slidelink slideid="_player.680CGwUAaSX.641pSMeVBq2" displaytext="Glossary" expand="true" />
                </links>
            </slidelink>
            <slidelink slideid="_player.680CGwUAaSX" displaytext="Menu and Resources" expand="true">
                <links>
                    <slidelink slideid="_player.680CGwUAaSX.6AopJzqESlV" displaytext="Menu" expand="true" />
                    <slidelink slideid="_player.680CGwUAaSX.6U6k0n98l71" displaytext="Resources" expand="true" />
                </links>
            </slidelink>
        </links>
    </outline>
</nav_data>

My objective is to find the have each slidelink display the "displaytext" attributes and apply the slideid attributes to them.

I'm currently able to display the 2 attributes for the first ChildNode.

My issues are:

  1. I do not know how to create an array to display these attributes for all childNodes.
  2. I do not know how to create a relative URL for the slidelink and display the displaytext for the slidelink.

I am not able to change the XML at all as this is produced using an courseware development IDE.

My current scripts display the 2 items and are as follows:

<script>
var loadscenelink = function(){
      $.ajax({
        type: "GET",
        url: "story_content/frame.xml",
        dataType: "xml",
        success: function(xml){
                var surl = $($(xml).find('links')[0].childNodes[0].attributes["slideid"]);
                var slinkvalue = surl[0].nodeValue;
                var slinkcode = $(surl);
                console.log(surl); /* Firefox Degugging */
                console.log(slinkvalue); /* Firefox Degugging */
                var player = GetPlayer();
                player.SetVar("SceneLink",slinkvalue);
        }
    });
};
</script>

<script>
var loadscenelinkname = function(){
      $.ajax({
        type: "GET",
        url: "story_content/frame.xml",
        dataType: "xml",
        success: function(xml){
                var sln = $($(xml).find('links')[0].childNodes[0].attributes["displaytext"]);
                var slinkname = sln[0].nodeValue;
                var slinktitle = $(sln);
                console.log(sln); /* Firefox Degugging */
                console.log(slinkname); /* Firefox Degugging */
                var player = GetPlayer();
                player.SetVar("SceneLinkName",slinkname);
        }
    });
};
</script>

Any advise or assistance would be greatly appreciated.

Best Regards,
Dennis Hall

Thanks iamthwee:

I am a PHP developer and have alreadey used jQuery for menus in PHP. Unfortunately, for this situation, I cannot do that. This project is e-Learning related and I can only deal with the ouptut files generated by the dev. product (which are HTML, JS, XML, and SWF.

Great answer, however, if it was a PHP site - Ièd have done it that way.

Best Regards,
Dennis Hall

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.