Question: is it possible to parse XML with Javascript in ePUB for viewing in iBooks?
Answer: yes
A very basic example would consist of an xhtml file that contained for example two <div> tags. One with the id="title" and the other id="text". At the foot of which before the closing tag of the body text you would write:
<script type="text/javascript">
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","document.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
t=xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
x=xmlDoc.getElementsByTagName("text")[0].childNodes[0].nodeValue;
document.getElementById("title").innerHTML=t;
document.getElementById("text").innerHTML=x;
</script>
You would then in the content.opf file make sure that where the XML documents are listed that you insert in the spine listing linear="no".
The corresponding XML would look something like this:
<root>
<title>This is the title</title>
<text>This is the text</text>
</root>
This is iBooks specific, since I know that Bluefire Reader and Sony's library software display the script as text, and no doubt plenty of others do too. I've also only performed limited testing in iBooks, but it strikes me that being able to parse XML opens many doors for complex and dynamic books.
Answer: yes
A very basic example would consist of an xhtml file that contained for example two <div> tags. One with the id="title" and the other id="text". At the foot of which before the closing tag of the body text you would write:
<script type="text/javascript">
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","document.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
t=xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
x=xmlDoc.getElementsByTagName("text")[0].childNodes[0].nodeValue;
document.getElementById("title").innerHTML=t;
document.getElementById("text").innerHTML=x;
</script>
You would then in the content.opf file make sure that where the XML documents are listed that you insert in the spine listing linear="no".
The corresponding XML would look something like this:
<root>
<title>This is the title</title>
<text>This is the text</text>
</root>
This is iBooks specific, since I know that Bluefire Reader and Sony's library software display the script as text, and no doubt plenty of others do too. I've also only performed limited testing in iBooks, but it strikes me that being able to parse XML opens many doors for complex and dynamic books.
Comments
Post a Comment