Re: [xmljs-users] Parser error: expected document node...
Brought to you by:
djoham,
witchhunter
From: Ricky V. <rv...@da...> - 2006-08-24 13:49:34
|
I have found xml.js has to sacrifice performance for cross browser compatibility (not taking anything away from it, because it is cool). However, if your project allows you to code for exclusively Firefox/IE, attached is some code that I use to do ajax calls to Servlets and ASP apps. //** BEGIN CODE /** XHConn - Simple XMLHTTP Interface - bf...@gm... - 2005-04-08 ** ** Code licensed under Creative Commons Attribution-ShareAlike License ** ** http://creativecommons.org/licenses/by-sa/2.0/ ** var myConn = new XHConn(); if (!myConn) alert("XMLHTTP not available. Try a newer/better browser."); var fnWhenDone = function (oXML) { alert(oXML.responseText); }; myConn.connect("mypage.php", "POST", "foo=bar&baz=qux", fnWhenDone); */ function XHConn() { var xmlhttp, bComplete = false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; }}} if (!xmlhttp) return null; this.connect = function(sURL, sMethod, sVars, fnDone) { if (!xmlhttp) return false; bComplete = false; sMethod = sMethod.toUpperCase(); try { if (sMethod == "GET") { xmlhttp.open(sMethod, sURL+"?"+sVars, true); sVars = ""; } else { xmlhttp.open(sMethod, sURL, true); xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4 && !bComplete) { bComplete = true; fnDone(xmlhttp); }}; xmlhttp.send(sVars); } catch(z) { return false; } return true; }; return this; } //** END CODE Ricky Vega (817) 313-6873 -----Original Message----- From: xml...@li... [mailto:xml...@li...] On Behalf Of Tornick, Edward x. -ND Sent: Thursday, August 24, 2006 8:32 AM To: David Joham; xml...@li... Subject: Re: [xmljs-users] Parser error: expected document node... I am using a javascript package called prototype.js on the client to do an ajax call to a servlet. The response ends up in a variable in a javascript function on the client. var xmlResponse = originalRequest.responseText; When I look at the response it looks like this... <?xml version="1.0"?> <vendor> <name> harry </name> <address> 100 Cherry Tree Lane </address> </vendor> xmlResponse is being processed by xmldos.js ======================================================== var objDom = new XMLDoc(xmlResponse, xmlError); var objDomTree = objDom.docNode; var tag1Elements = objDomTree.getElements("name"); var element = tag1Elements[0]; var name = element.getText(); var tag1Elements = objDomTree.getElements("address"); var element = tag1Elements[0]; var address = element.getText(); alert(name); alert(address); ========================================================== The nodes are being found. And my alerts show "harry" and "100 cherry Tree Lane" but the error Routine xmlError is called as each node is parsed. I will try the other parser as you suggested if I don't get anywhere with this. Thanks David Ed -----Original Message----- From: David Joham [mailto:dj...@ya...] Sent: Thursday, August 24, 2006 9:16 AM To: Tornick, Edward x. -ND; xml...@li... Subject: Re: [xmljs-users] Parser error: expected document node... Nothings obviously wrong, but I have a suspicion about your response.setContentType("text/xml"); line. How are you getting the data into xmljs? Is it going to a frame something else? Normally, you just write the XML directly into the web page (escaping characters as necessary) in a textarea or something else. I'm curious if what you're doing might be causing the problem somehow. What happens if you use the w3c parser? Does the same error occur? Can you send the list a minimal sample HTML page that causes this error? If we have that, we can probably dive into it and figure out what's going wrong... David --- "Tornick, Edward x. -ND" <Edw...@es...> wrote: > I am using the domparser.js and I get this error... Error expected > document node found text. > > It is from this code in the xmldom.js.... > ====================================================================== > > > function _XMLDoc_handleNode(current) > { > /* > function: _XMLDoc_handleNode > Author: mi...@id... > Description: > adds a markup element to the document */ > if ((current.nodeType=='COMMENT') && (this.topNode!=null)) { > return this.topNode.addElement(current); > } > else if ((current.nodeType=='TEXT') || > (current.nodeType=='CDATA')) { > // if the current node is a text node: > // if the stack is empty, and this text node isn't just > whitespace, we have > // a problem (we're not in a document element) > if(this.topNode==null) { > if (trim(current.content,true,false)=="") { > return true; > } > else { > return this.error("expected document node, found: " + > current); > } > } > else { > // otherwise, append this as child to the element at the > top of the stack > return this.topNode.addElement(current); > } > ====================================================================== > == The values are being parsed correctly but the error is showing up: > My server side code that generates the xml looks like this.... > > response.setContentType("text/xml"); > PrintWriter out = response.getWriter(); > out.println("<?xml version=\"1.0\"?>"); > out.println("<vendor>"); > out.println("<name>"); > out.println("harry"); > out.println("</name>"); > out.println("<address>"); > out.println("100 Cherry Tree Lane"); > out.println("</address>"); > out.println("</vendor>"); > > Is anything obviously wrong with this???? > > Thanks, > Ed > > > -------------------------------------------------------------------- > > ----- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier Download IBM WebSphere Application Server v.1.0.1 based on > Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=1216 > 42> _______________________________________________ > xmljs-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmljs-users > ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ xmljs-users mailing list xml...@li... https://lists.sourceforge.net/lists/listinfo/xmljs-users |