使用jQuery / XML显示特定信息

时间:2012-04-17 14:21:16

标签: jquery xml

我使用jQuery用XML数据填充了一个select元素,这并不太难。我现在正试图找到一种方法来显示分配给其自己的单独div区域中的select元素中的特定元素的信息。到目前为止,这是我的代码的例子:

    $('.selectspeak').live('change', function() {

                $("#mainOutput").empty();

                $(g_playDOM).find("SPEECH").each(function(){

                    var speaker = $(".selectspeak").val();
                    var line = $(this).find("LINE").text();

                $("#mainOutput").append("<div class='speakerClass'>" + "Speaker: " + speaker + "<br />" + " <div class='speakerClassLine'>" + "<br />" + "Line: " + line + "</div>");

            });

});

上面的代码基本上用扬声器数据填充了select标签,没问题。但是在选择扬声器时,它只是将数据显示为正常,而不是分配给扬声器的数据。如何确保在选择扬声器时仅显示指定的信息?

我一直试图破解这个坚果几个小时,进展很少,所以在正确的方向上轻推就太棒了! : - )

谢谢!

更新:我添加了一个指向实时项目的链接。只需在左侧选择一个游戏,然后您就可以在右侧看到我正在谈论的选择元素。感谢。

http://scmweb.infj.ulst.ac.uk/~B00351504/COM601/assignment_2/siab.html

第二次更新:

请求的某些XML行:

<PLAY>
<TITLE>The Merchant of Venice</TITLE>
<FM>
<P>
ASCII text placed in the public domain by Moby Lexical Tools, 1992.
</P>
<P>SGML markup by Jon Bosak, 1992-1994.</P>
<P>XML version by Jon Bosak, 1996-1999.</P>
<P>
The XML markup in this version is Copyright © 1999 Jon Bosak. This work may freely be distributed on condition that it not be modified or altered in any way.
</P>
</FM>
<PERSONAE>
<TITLE>Dramatis Personae</TITLE>
<PERSONA>The DUKE OF VENICE.</PERSONA>
<PGROUP>
<PERSONA>The PRINCE OF MOROCCO</PERSONA>
<PERSONA>The PRINCE OF ARRAGON</PERSONA>
<GRPDESCR>suitors to Portia.</GRPDESCR>
</PGROUP>
<PERSONA>ANTONIO, a merchant of Venice.</PERSONA>
<PERSONA>BASSANIO, his friend, suitor likewise to Portia.</PERSONA>
<PGROUP>
<PERSONA>SALANIO</PERSONA>
<PERSONA>SALARINO</PERSONA>
<PERSONA>GRATIANO</PERSONA>
<PERSONA>SALERIO</PERSONA>
<GRPDESCR>friends to Antonio and Bassanio.</GRPDESCR>
</PGROUP>
<PERSONA>LORENZO, in love with Jessica.</PERSONA>
<PERSONA>SHYLOCK, a rich Jew.</PERSONA>
<PERSONA>TUBAL, a Jew, his friend.</PERSONA>
<PERSONA>LAUNCELOT GOBBO, the clown, servant to SHYLOCK.</PERSONA>
<PERSONA>OLD GOBBO, father to Launcelot.</PERSONA>
<PERSONA>LEONARDO, servant to BASSANIO.</PERSONA>
<PGROUP>
<PERSONA>BALTHASAR</PERSONA>
<PERSONA>STEPHANO</PERSONA>
<GRPDESCR>servants to PORTIA.</GRPDESCR>
</PGROUP>
<PERSONA>PORTIA, a rich heiress.</PERSONA>
<PERSONA>NERISSA, her waiting-maid.</PERSONA>
<PERSONA>JESSICA, daughter to SHYLOCK.</PERSONA>
<PERSONA>
Magnificoes of Venice, Officers of the Court of Justice, Gaoler, Servants to Portia, and other Attendants.
</PERSONA>
</PERSONAE>
<SCNDESCR>
SCENE Partly at Venice, and partly at Belmont, the seat of PORTIA, on the Continent.
</SCNDESCR>
<PLAYSUBT>THE MERCHANT OF VENICE</PLAYSUBT>
<ACT>
<TITLE>ACT I</TITLE>
<SCENE>
<TITLE>SCENE I. Venice. A street.</TITLE>
<STAGEDIR>Enter ANTONIO, SALARINO, and SALANIO</STAGEDIR>
<SPEECH>
<SPEAKER>ANTONIO</SPEAKER>
<LINE>In sooth, I know not why I am so sad:</LINE>
<LINE>It wearies me; you say it wearies you;</LINE>
<LINE>But how I caught it, found it, or came by it,</LINE>
<LINE>What stuff 'tis made of, whereof it is born,</LINE>
<LINE>I am to learn;</LINE>
<LINE>And such a want-wit sadness makes of me,</LINE>
<LINE>That I have much ado to know myself.</LINE>
</SPEECH>

1 个答案:

答案 0 :(得分:0)

我认为您必须过滤所选的“SPEECH”项目。

$('.selectspeak').live('change', function() {

                $("#mainOutput").empty();

                $(g_playDOM).find("SPEECH").each(function(){

                    var speaker = $(".selectspeak").val();
                    //I'm checking if this 'SPEECH' is by "SPEAKER"
                    if($(this).find("SPEAKER").text()==speaker){


                    var line = $(this).find("LINE").text();
                    $("#mainOutput").append("<div class='speakerClass'>" + "Speaker: " + speaker + "<br />" + " <div class='speakerClassLine'>" + "<br />" + "Line: " + line + "</div>");
                    }



            });

});​

在这里,我检查了所选的“SPEECH”项是否属于“Speaker”。