You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by mb...@netscape.net on 2001/04/05 10:23:50 UTC
trouble using DomParser in JSP
HEllo,
I'm trying to parse an XML document with DOm method into a JSP.
I'm using the method hasAttributes from Node interface. but I'm always catching an Exception "Method hasAttributes() not found in interface org.w3c.dom.Node".
the code that I'm including in my JSP is something like this:
<%
DOMParser dprDomParser = new DOMParser();
try{
dprDomParser.parse(new InputSource(new ByteArrayInputStream(
strXml.getBytes())));
}
catch(Exception expE){
expE.printStackTrace();
}
/**********************************************************/
/* Code for retrieaving a node (nod) from the XmlDocument */
// etc...
if (nod.hasAttributes()){
out.println("OK");
}
else{
out.println("NO");
}
%>
__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: trouble using DomParser in JSP
Posted by Andy Clark <an...@apache.org>.
mbencharrada@netscape.net wrote:
> I'm using the method hasAttributes from Node interface. but I'm
> always catching an Exception "Method hasAttributes() not found in
> interface org.w3c.dom.Node".
Class path issue -- it's picking up DOM Level 1 classes before
DOM Level 2 (where the method hasAttributes was introduced).
> dprDomParser.parse(new InputSource(new ByteArrayInputStream(
> strXml.getBytes())));
This is a bad idea in general. If you already have it as a Java
String, then don't go back to bytes -- just use a StringReader
object. However, there may be a deeper problem here depending
on how you got the strXml String reference. In other words, are
you sure that it was transcoded into Unicode correctly? If not,
then get ahold of the real bytes coming in (not the ones from
the String object) and use the ByteArrayInputStream as before.
Otherwise you could have corrupted data and/or the parser could
barf because the bytes don't match the encoding specified in
the XMLDecl of the XML document instance.
--
Andy Clark * IBM, TRL - Japan * andyc@apache.org