Error reading from XML file
pI'm having a problem reading from xml file. When I try to parse the data
it gives me the error: strongjunk after document element/strong/p pI think
the problem is in the
xmlDoc=parser.parseFromString(localStorageRow,text/xml) because I already
checked the xml file and it seems to have no problem there./p pthe
objective is to insert, in the search tab, the title of the image and then
return the image path that is in My_database.xml /p pstrongmy xml
My_database.xml/strong:/p precodelt;?xml version=1.0 encoding=utf-8?gt;
lt;imagesgt; lt;image class=beachgt; lt;IDgt;2332172539lt;/IDgt;
lt;pathgt;Images/beach/img_2.jpglt;/pathgt; lt;titlegt;Cannon Beach sunset
cloudslt;/titlegt; lt;descriptiongt;nulllt;/descriptiongt;
lt;latitudegt;45.88992lt;/latitudegt;
lt;longitudegt;-123.96389lt;/longitudegt; lt;dategt;Sat Mar 01 17:55:01
GMT 2008lt;/dategt; lt;dominantcolorgt;#A0A080lt;/dominantcolorgt;
lt;/imagegt; /code/pre pstrongmy html/javascript code:/strong/p
precodelt;!DOCTYPEgt; lt;htmlgt; lt;headgt; lt;meta
http-equiv=Content-Type content=text/html; charset=utf-8 /gt;
lt;titlegt;Search local storagelt;/titlegt; lt;/headgt; lt;bodygt; This
page will allow the user to search the content saved in your local
storage.lt;br /gt; Search By image name, results will be returned by path
of the image.lt;br /gt; lt;form action=IMAGE.html method=getgt; Search By
title : lt;input type=text name=txtA /gt;lt;br /gt; lt;input type=submit
value=Submit /gt; lt;/formgt; lt;div id=results_IDgt;lt;/divgt; lt;script
type=text/javascriptgt; var localStorageRow =
localStorage.getItem(localStorage.key(i)) ; var author_query =
getUrlVars()[txtA]; if (typeof(author_query) == undefined || author_query
=== ) { } else { for ( var i = 0 ; i lt; localStorage.length; i++) { var
localStorageRow = localStorage.getItem(localStorage.key(i));
//document.write(localStorageRow); if (window.DOMParser) { parser=new
DOMParser(); xmlDoc=parser.parseFromString(localStorageRow,text/xml);
//text/xml } else // Internet Explorer { xmlDoc=new
ActiveXObject(Microsoft.XMLDOM); xmlDoc.async=false;
xmlDoc.loadXML(localStorageRow); } for ( var k = 0 ; k lt;
xmlDoc.firstChild.childNodes.length ; k++ ) { if (
xmlDoc.firstChild.childNodes[k].nodeName === title ) {
//document.write(xmlDoc.firstChild.childNodes[k].textContent); var
auth_row = xmlDoc.firstChild.childNodes[k].textContent; var authMatch =
auth_row.match(new RegExp(author_query, i)); if ( authMatch ) { for ( var
p = 0 ; p lt; xmlDoc.firstChild.childNodes.length ; p ++ ) { if (
xmlDoc.firstChild.childNodes[p].nodeName == 'path' ) {
document.getElementById(results_ID).innerHTML +=
xmlDoc.firstChild.childNodes[p].textContent+lt;br /gt;;
//document.getElementById(results_ID).innerHTML +=
xmlDoc.firstChild.childNodes[p].textContent+lt;br /gt;;
//document.write(x); } } } } } } } //GET URL VARS function function
getUrlVars() { var vars = {}; var parts =
window.location.href.replace(/[?amp;]+([^=amp;]+)=([^amp;]*)/gi,
function(m,key,value) { vars[key] = value; }); return vars; }
lt;/scriptgt; lt;/bodygt; lt;/htmlgt; /code/pre pI just started with html5
and javascript, Ive already searched the problem that I'm having, but I
had no luck to find the answer. Thanks in advance./p
No comments:
Post a Comment