<!-- XMLbible.html
 -- James Skon April 23, 2011
 -- Mount Vernon Nazarene University
 -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<title>XML Bible Demo - MVNU(Jim Skon)</title>
<script type="text/javascript">
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  biblePath="/csc3004/XMLBible/kjv_by_book/"

function getresponse () {
  var b=document.getElementById('book').value;
  var c=document.getElementById('chapter').value;
  var v=parseInt(document.getElementById('verse').value);
  var n=parseInt(document.getElementById('numVerse').value);

  var XMLBook = biblePath + b + ".xml";
  xmlhttp.open("GET",XMLBook,false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML;

  document.write("<h1><font color=blue>MVNU CS Bible XML Demo Program</font></h1><br>");
  var i = 0;
  try {
    for (i = 0; i < n;i++) {
      vtext = getVerse(b,c,v+i);
	  document.write("<p>"+vtext+"</p>");
    }
  }
  catch(error) {
    if (error == "no chapter") {
      document.write("<b><i>No such chapter "+c+"</i></b>");
    }      
    if (error == "no verse") {
	  if (i == 0)
        document.write("<b><i>No such verse "+(v+i)+"</i></b>");
    }
  }
      
}

function getVerse(bk,ch,ver)
{
  var verseOutput = xmlDoc.getElementsByTagName("book")[0].getAttribute("name"); 
  var c=xmlDoc.getElementsByTagName("chapter")[ch-1];
  if (c==null) throw "no chapter";
  verseOutput += " ";
  verseOutput += c.getAttribute("number"); 
  var v=c.getElementsByTagName("verse")[ver-1]
  if (v==null) throw "no verse";
  verseOutput += ":";
  verseOutput += v.getAttribute("number");
  verseOutput += " ";
  for (j=0; j<v.childNodes.length;j++) {
    if (v.childNodes[j].nodeType == 3) {
        verseOutput += v.childNodes[j].nodeValue;
        verseOutput += " ";
    } 
    if (v.childNodes[j].nodeType == 1) {
        if (v.childNodes[j].nodeName=="em") {
           verseOutput += "<i>";
           verseOutput += v.childNodes[j].childNodes[0].nodeValue;
           verseOutput += "</i> ";
        }
        if (v.childNodes[j].nodeName=="strongs") {
           if (v.childNodes[j].childNodes[0] != null) {
             verseOutput += v.childNodes[j].childNodes[0].nodeValue;
           }
           // use hasAttribute(attributename) to figure out the right attribute
		   if (v.childNodes[j].hasAttribute("hebrew")) {
             verseOutput += "<i><font size=1 color=blue><sub>";
             verseOutput += v.childNodes[j].getAttribute("hebrew");
             verseOutput += "</sub></font></i> ";
           }
		   if (v.childNodes[j].hasAttribute("greek")) {
             verseOutput += "<i><font size=1 color=green><sub>";
             verseOutput += v.childNodes[j].getAttribute("greek");
             verseOutput += "</sub></font></i> ";
		   }
           if (v.childNodes[j].hasAttribute("number")) {
             verseOutput += "<i><font size=1 color=teal><sub>";
             verseOutput += v.childNodes[j].getAttribute("number");
             verseOutput += "</sub></font></i> ";
           }
       }
    }
}
return(verseOutput);
}
</script>
</head>
<body>
<form>
<table>

<TR>
<TD ALIGN=RIGHT VALIGN=TOP>Book</TD>

<TD ALIGN=LEFT VALIGN=TOP><INPUT NAME="book" TYPE="text" MAXLENGTH=2  id=book></TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>Chapter</TD>
<TD ALIGN=LEFT VALIGN=TOP><INPUT NAME="chapter" TYPE="text" MAXLENGTH=3  id=chapter></TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>Verse</TD>
<TD ALIGN=LEFT VALIGN=TOP><INPUT NAME="verse" TYPE="text" MAXLENGTH=3 id=verse></TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP>Numbers of Verses</TD>
<TD ALIGN=LEFT VALIGN=TOP><INPUT NAME="numVerse" TYPE="text" MAXLENGTH=3 id=numVerse></TD>
</TR>

</TABLE>

<p>
<input type="submit" onclick="javascript: getresponse()" name="submit" value="Submit" />
</p>

<div id = "responseArea">
</div>
</form>
</body>
</html>

-- JimSkon - 2011-04-25

Topic revision: r2 - 2011-04-27 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback