I was helping someone with some jQuery to read XML files of Shakespeare plays and this is what I came up with. Very incomplete but he so I can reference it in future….
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>shaXpeare</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/cupertino/jquery-ui.css" rel="stylesheet"/> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function(){ /* Initialise jQuery UI components */ $("#accordion").accordion(); $("#home-button").button(); $("#contents-button").button(); /* Hide the play out when page loads */ $("#play-output, #contents-button").hide(); /* Home button click event */ $("#home-button").click(function() { $("#accordion").fadeIn(1000); $("#play-output, #contents-button").hide(); }); $(".play_choose").change(function(){ $('.act_choose').children().remove(); $('.act_choose').append('<option value="">Choose an Act</option>'); var play = $("select.play_choose option:selected").val(); $.ajax({ type:"GET", url: "plays/" + play, dataType: "xml", success: function(xml) { $(xml).find('ACT').each(function(){ var act = $(this).find('TITLE:first').text(); $('.act_choose').append('<option value="'+act+'">'+act+'</option>'); }); // end } });//end .ajax }); $(".act_choose").change(function(){ $('.scene_choose').children().remove(); $('.scene_choose').append('<option value="">Choose a Scene</option>'); var play = $("select.play_choose option:selected").val(); var act = $("select.act_choose option:selected").val(); $.ajax({ type:"GET", url: "plays/" + play, dataType: "xml", success: function(xml) { $(xml).find('ACT').each(function(){ // TODO is is the act chosen in act_select? // If so get the scenes if(act==$(this).find('TITLE:first').text()){ $(this).find('SCENE').each(function(){ var scene = $(this).find('TITLE').text(); $('.scene_choose').append('<option value="'+scene+'">'+scene+'</option>'); }); // end } //var act = $(this).find('TITLE:first').text(); $('.act_choose').append('<option value="'+act+'">'+act+'</option>'); }); // end } });//end .ajax }); $(".scene_choose").change(function(){ $('#scene_output').empty(); $('#output').empty(); var linecount=0; var play = $("select.play_choose option:selected").val(); var act = $("select.act_choose option:selected").val(); var scene = $("select.scene_choose option:selected").val(); //alert(play + '' + act + '' +scene); $.ajax({ type:"GET", url: "plays/" + play, dataType: "xml", success: function(xml) { $(xml).find('ACT').each(function(){ // TODO is is the act chosen in act_select? // If so get the scenes if(act==$(this).find('TITLE:first').text()){ $(this).each(function(){ // We are now going through each line of the act $(this).find("SCENE").each(function() { if ($(this).find("TITLE").text() == scene){ $(this).children().each(function() { elementType = $(this).get(0).tagName; switch (elementType){ case "TITLE": $("#output").append("<h2>" + $(this).text() + "</h2>"); break; case "STAGEDIR": $("#output").append("<h3>" + $(this).text() + "</h3>"); break; case "SPEECH": $(this).find("SPEAKER:first").each(function() { $("#output").append("<span class='speaker'>" + $(this).text() + "</span><br>"); }); $(this).find("LINE").each(function() { $("#output").append("<sup>"+linecount+"</sup><span class='speech'>" + $(this).text() + "</span>"); linecount++; }); $("#output").append("<br>"); break; } // End of SWITCH block }); //end each children } //end of if scene TITLE text scene var });//end find SCENE }); // end this each function } //end if act == TITLE:first }); // end find ACT } //end function xml });//end .ajax }); //end .scene_choose $("#search_button").click(function(){ var play = $("select.play_choose option:selected").val(); var searchphrase = $('#searchfield').val(); $.ajax({ type:"GET", url: "plays/" + play, dataType: "xml", success: function(xml) { $(xml).find('LINE:contains("'+searchphrase+'")').each(function(){ $('#search_results').append($(this).text()+'<hr>'); }); // end } });//end .ajax }); //end search button function $(".charSelect").click(function() { $("#play-chars").html("Characters .... <br>"); var play = $(this).parent().attr("id"); $.ajax({ type:"GET", url: "plays/" + play, dataType: "xml", success: function(xml) { $(xml).find('PERSONA').each(function(){ var character = $(this).text(); $("#play-chars").append(character + "<br>"); }); // end } });//end .ajax });//end charSelect click function }); // end doc ready </script> <style> body{ font-family: arial, helvetica, sans-serif; font-size:0.9em; } .speaker{ font-weight:bold; } .speech{ color:#000; } h2{font-size:1.2em; color:#0073AD;} h3{font-size:1.1em; color:#109EE5;} sup{color:#c0c0c0;} </style> </head> <body> <div id="wrapper"> <div id="header"> <h1>shaXpeare</h1><h3>The plays of Shakespeare with added X Factor</h3> </div><!-- end Header --> <div id="sidebar"> <div id="home-button">Home</div> <div id="contents-button">Contents</div> </div><!-- end Sidebar --> <div id="content"> <h2 id="play-title">Play</h2> Choose a Play: <select class="play_choose"> <option selected="yes" value="">Choose a Play</option> <option value="" class="select_heading">TRAGEDIES</option> <option value="a_and_c.xml">Antony and Cleopatra</option> <option value="coriolan.xml">Coriolanus</option> <option value="hamlet.xml">Hamlet</option> <option value="j_caesar.xml">Julius Caesar</option> <option value="lear.xml">King Lear</option> <option value="macbeth.xml">Macbeth</option> <option value="othello.xml">Othello</option> <option value="r_and_j.xml">Romeo and Juliet</option> <option value="timon.xml">Timon of Athens</option> <option value="titus.xml">Titus Andronicus</option> <option value="" class="select_heading"></option> <option value="" class="select_heading">HISTORIES</option> <option value="hen_iv_1.xml">Henry IV, Part I</option> <option value="hen_iv_2.xml">Henry IV, Part II</option> <option value="hen_v.xml">Henry V</option> <option value="hen_vi_1.xml">Henry VI, Part I</option> <option value="hen_vi_2.xml">Henry IV, Part II</option> <option value="hen_vi_3.xml">Henry IV, Part III</option> <option value="hen_viii.xml">Henry VIII</option> <option value="john.xml">King John</option> <option value="rich_ii.xml">Richard II</option> <option value="rich_iii.xml">Richard II</option> <option value="" class="select_heading"></option> <option value="" class="select_heading">COMEDIES</option> <option value="all_well.xml">All's Well That Ends Well</option> <option value="as_you.xml">As You Like It</option> <option value="com_err.xml">The Comedy of Errors</option> <option value="cymbelin.xml">Cymbeline</option> <option value="lll.xml">Love's Labours Lost</option> <option value="m_for_m.xml">Measure for Measure</option> <option value="m_wives.xml">The Mercy Wives of Windsor</option> <option value="merchant.xml">The Merchant of Venice</option> <option value="dream.xml">A Midsummer Night's Dream</option> <option value="much_ado.xml">Much Ado About Nothing</option> <option value="pericles.xml">Pericles, Prince of Tyre</option> <option value="taming.xml">The Taming of the Shrew</option> <option value="tempest.xml">The Tempest</option> <option value="troilus.xml">Troilus and Cressida</option> <option value="t_night.xml">Twelfth Night</option> <option value="two_gent.xml">Two Gentlemen of Verona</option> <option value="win_tale.xml">The Winter's Tale</option> </select><br /> <div id="accordion"> <h3><a href="#">Scene Finder</a></h3> <div> Choose an Act and Scene to display.<br> Act: <select class="act_choose"> <option selected="yes" value="">Choose a Play first</option> </select><br /> Scene: <select class="scene_choose"> <option selected="yes" value="">Choose a Play and Act first</option> </select> <div id="output"></div> </div> <h3><a href="#">Search a Play</a></h3> <div> Search the Play: <input type="text" id="searchfield" class="searchfield" /><input type="button" value="Search" class="search_button" id="search_button" /> <div class="search_results" id="search_results" ></div> </div> <h3><a href="#">Character Finder</a></h3> <div> <h4>Tragedies</h4> <ul> <li id="a_and_c.xml"><a href="#" id="a_and_c.xml" class="playSelect">Antony and Cleopatra</a> (<a href="#" class="charSelect">Characters</a>) </li> <a href="#"><li id="coriolan.xml" class="playSelect">Coriolanus</li></a> (<a href="#" class="charSelect">Characters</a>) </li> <a href="#"><li id="hamlet.xml" class="playSelect">Hamlet</li></a>(<a href="#" class="charSelect">Characters</a>) </li> <a href="#"><li id="j_caesar.xml" class="playSelect">Julius Caesar</li></a>(<a href="#" class="charSelect">Characters</a>) </li> <a href="#"><li id="lear.xml" class="playSelect">King Lear</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="macbeth.xml" class="playSelect">Macbeth</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="othello.xml" class="playSelect">Othello</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="r_and_j.xml" class="playSelect">Romeo and Juliet</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="timon.xml" class="playSelect">Timon of Athens</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="titus.xml" class="playSelect">Titus Andronicus</li></a> (<a href="#" class="charSelect">Characters</a>) </ul> <h4>Histories</h4> <ul> <a href="#"><li id="hen_iv_1.xml" class="playSelect">Henry IV, Part I</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="hen_iv_2.xml" class="playSelect">Henry IV, Part II</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="hen_v.xml" class="playSelect">Henry V</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="hen_vi_1.xml" class="playSelect">Henry VI, Part I</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="hen_vi_2.xml" class="playSelect">Henry VI, Part II</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="hen_vi_3.xml" class="playSelect">Henry VI, Part III</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="hen_viii.xml" class="playSelect">Henry VIII</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="john.xml" class="playSelect">King John</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="rich_ii.xml" class="playSelect">Richard II</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="rich_iii.xml" class="playSelect">Richard III</li></a> (<a href="#" class="charSelect">Characters</a>) </ul> <h4>Comedies</h4> <ul> <a href="#"><li id="all_well.xml" class="playSelect">All's Well That Ends Well</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="as_you.xml" class="playSelect">As You Like It</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="com_err.xml" class="playSelect">The Comedy of Errors</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="cymbelin.xml" class="playSelect">Cymbeline</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="lll.xml" class="playSelect">Love's Labours Lost</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="m_for_m.xml" class="playSelect">Measure for Measure</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="m_wives.xml" class="playSelect">The Merry Wives of Windsor</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="merchant.xml" class="playSelect">The Merchant of Venice</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="dream.xml" class="playSelect">A Midsummer Night's Dream</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="much_ado.xml" class="playSelect">Much Ado About Nothing</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="pericles.xml" class="playSelect">Pericles, Prince of Tyre</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="taming.xml" class="playSelect">The Taming of The Shrew</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="tempest.xml" class="playSelect">The Tempest</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="troilus.xml" class="playSelect">Troilus and Cressida</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="t_night.xml" class="playSelect">Twelth Night</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="two_gent.xml" class="playSelect">Two Gentlemen of Verona</li></a> (<a href="#" class="charSelect">Characters</a>) <a href="#"><li id="win_tale.xml" class="playSelect">The Winter's Tale</li></a> (<a href="#" class="charSelect">Characters</a>) </ul> <div id="play-chars"></div> </div> </div><!-- END Accordion--> <div id="play-output"></div><!-- END Play Output--> </div><!-- END Content--> <br class="clearfloat" /> <div id="footer"> <p>Footer</p> </div><!-- END Footer--> </div><!-- END Wrapper--> </body> </html> |

