You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Anthony Ikeda <an...@proxima-tech.com.au> on 2001/05/28 08:46:15 UTC
returning a node (I can't find a solution anywhere!)
I know this may be a basic question, but I've tried every possible option I can think of. Simply put, all I'm trying to do, is add a "toXML()" method to a class, which converts my data into an Element which is returned to the calling object:
public class headache{
public Element toXML(){
.....
return Element;
}
}
DocumentImpl doc = new DocumentImpl();
Element root = doc.createElement("root");
headache h = new headache();
Element e = headache.toXML();
root.appendChild(e);
Running this code I get:
Context log: path="" Error in qResults service() : org/w3c/dom/DOMException
java.lang.InstantiationError: org/w3c/dom/DOMException
(Mind you, there is no such thing as a java.lang.InstantiationError, but there is a java.lang.InstantiationException)
I've tried setting up a cloneNode(node,true) at the "headache" class side as well as on the calling class side:
public class headache{
public Node toXML(){
.....
return Element.cloneNode(true);
}
}
DocumentImpl doc = new DocumentImpl();
Element root = doc.createElement("root");
headache h = new headache();
Element e = headache.toXML();
root.appendChild(e);
This returns the same. If I try to use importNode(node,true) on the calling class side:
rott.appendChild(doc.importNode(headache.toXML(),true));
I get:
Context log: path="" Error in qResults service() : null
java.lang.NoSuchMethodError
at org.apache.xerces.dom.DocumentImpl.importNode(DocumentImpl.java:888)
I'm using Xerces 1.4.0 and JDK1.3. The code is running in servlets.
Cheers,
Anthony
Re: returning a node (I can't find a solution anywhere!)
Posted by Anthony Ikeda <an...@proxima-tech.com.au>.
Thanks Andy,
I was hoping to avoid having to pass the doc, but it is a much better
solution although I'll have to work out why JBuilder didn't set the
"required" libraries in order as I set in the Project properties. Oh well,
thats another mailing list.
Cheers,
Anthony Ikeda
----- Original Message -----
From: "Andy Clark" <an...@apache.org>
To: <xe...@xml.apache.org>
Sent: Monday, May 28, 2001 5:27 PM
Subject: Re: returning a node (I can't find a solution anywhere!)
> Anthony Ikeda wrote:
> > I know this may be a basic question, but I've tried every possible
> > option I can think of. Simply put, all I'm trying to do, is add a
>
> Then you need to think harder! ;) Just kidding. This problem
> happens all of the time. There are a few problems that I see:
>
> > public class headache{
> > public Element toXML(){
> > .....
> > return Element;
> > }
> > }
> >
> > DocumentImpl doc = new DocumentImpl();
> > Element root = doc.createElement("root");
> >
> > headache h = new headache();
> > Element e = headache.toXML();
> > root.appendChild(e);
>
> 1) You're getting a WRONG_DOCUMENT_ERR because any node appended
> to a document must have been created using the same document
> factory. Therefore, your "headache#toXML" method must use
> the same document instance. Why don't you change the
> prototype to pass in the document, like so:
>
> public Element toXML(Document factory);
>
> > This returns the same. If I try to use importNode(node,true) on the
> > calling class side:
> >
> > rott.appendChild(doc.importNode(headache.toXML(),true));
> >
> > I get:
> >
> > Context log: path="" Error in qResults service() : null
> > java.lang.NoSuchMethodError
> >
> > at
> > org.apache.xerces.dom.DocumentImpl.importNode(DocumentImpl.java:888)
>
> Classpath problem. You are picking up the DOM Level 1 interfaces
> before the DOM Level 2 interfaces (which added importNode). Once
> this is fixed, the importNode should work but I wouldn't
> recommend it because this creates a copy of the imported node.
> Very wasteful.
>
> --
> Andy Clark * IBM, TRL - Japan * andyc@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: returning a node (I can't find a solution anywhere!)
Posted by Andy Clark <an...@apache.org>.
Anthony Ikeda wrote:
> I know this may be a basic question, but I've tried every possible
> option I can think of. Simply put, all I'm trying to do, is add a
Then you need to think harder! ;) Just kidding. This problem
happens all of the time. There are a few problems that I see:
> public class headache{
> public Element toXML(){
> .....
> return Element;
> }
> }
>
> DocumentImpl doc = new DocumentImpl();
> Element root = doc.createElement("root");
>
> headache h = new headache();
> Element e = headache.toXML();
> root.appendChild(e);
1) You're getting a WRONG_DOCUMENT_ERR because any node appended
to a document must have been created using the same document
factory. Therefore, your "headache#toXML" method must use
the same document instance. Why don't you change the
prototype to pass in the document, like so:
public Element toXML(Document factory);
> This returns the same. If I try to use importNode(node,true) on the
> calling class side:
>
> rott.appendChild(doc.importNode(headache.toXML(),true));
>
> I get:
>
> Context log: path="" Error in qResults service() : null
> java.lang.NoSuchMethodError
>
> at
> org.apache.xerces.dom.DocumentImpl.importNode(DocumentImpl.java:888)
Classpath problem. You are picking up the DOM Level 1 interfaces
before the DOM Level 2 interfaces (which added importNode). Once
this is fixed, the importNode should work but I wouldn't
recommend it because this creates a copy of the imported node.
Very wasteful.
--
Andy Clark * IBM, TRL - Japan * andyc@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: returning a node (I can't find a solution anywhere!)
Posted by Anthony Ikeda <an...@proxima-tech.com.au>.
Ignore this, it was a problem with JBuilder 4........
----- Original Message -----
From: Anthony Ikeda
To: xerces-j-user@xml.apache.org
Sent: Monday, May 28, 2001 4:46 PM
Subject: returning a node (I can't find a solution anywhere!)
I know this may be a basic question, but I've tried every possible option I can think of. Simply put, all I'm trying to do, is add a "toXML()" method to a class, which converts my data into an Element which is returned to the calling object:
public class headache{
public Element toXML(){
.....
return Element;
}
}
DocumentImpl doc = new DocumentImpl();
Element root = doc.createElement("root");
headache h = new headache();
Element e = headache.toXML();
root.appendChild(e);
Running this code I get:
Context log: path="" Error in qResults service() : org/w3c/dom/DOMException
java.lang.InstantiationError: org/w3c/dom/DOMException
(Mind you, there is no such thing as a java.lang.InstantiationError, but there is a java.lang.InstantiationException)
I've tried setting up a cloneNode(node,true) at the "headache" class side as well as on the calling class side:
public class headache{
public Node toXML(){
.....
return Element.cloneNode(true);
}
}
DocumentImpl doc = new DocumentImpl();
Element root = doc.createElement("root");
headache h = new headache();
Element e = headache.toXML();
root.appendChild(e);
This returns the same. If I try to use importNode(node,true) on the calling class side:
rott.appendChild(doc.importNode(headache.toXML(),true));
I get:
Context log: path="" Error in qResults service() : null
java.lang.NoSuchMethodError
at org.apache.xerces.dom.DocumentImpl.importNode(DocumentImpl.java:888)
I'm using Xerces 1.4.0 and JDK1.3. The code is running in servlets.
Cheers,
Anthony