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 Sampath K Settipalli <Sa...@genome.wi.mit.edu> on 2002/09/04 18:02:26 UTC
getElementByTagName
Hi ,
In the process of migrating from xml4j to Xerces I'm replacing
classes/interfaces from xml4j with that of from xerces.
For TXElement headel = TXElement.getElementNamed("Header") ;
I replaced with these two lines NodeList nl =
root.getElementsByTagName("Header"); //roor it DocumentElement
Element headel = (Element)nl.item(0).getFirstChild();
When I tried this at runtime it gives Exception in thread "main"
java.lang.ClassCastException: org.apache.xerces.dom.DeferredTextImpl at
this line
The xml document has a Element named Header with attributes in it & I
need to get the attributes . headel.getAttribute(Test");
How can get this work OR
Is there any better way to get Element with a tagName from a
DocumentElement and get attributes from it ?
Thanks in advance,
Sampath
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Where is com.ibm.xml.parser? (same as xerces?)
Posted by Richard Heintze <si...@yahoo.com>.
I'm trying to try out a simple test of IBM's Dav4J
Java library -- it is supposed to implement WebDAV, a
substitute for FTP.
So what does this have to do with xerces?
Apparently, I need xml4j in my class path but when I
download that, I get something that looks very similar
to xerces! I'm still getting these errors (below)!
Help!
thanks,
Siegfried
c:\dav4j_2_0_7\samples>set
CLASSPATH=.;C:\dav4j_2_0_7\dav4j.jar;C:\dav4j_2_0_7\dav4j;C:\dav4j_2_0_7\xml4j-4_0_1\xercesImpl.jar;C:\dav4j_2_0_7\xml4j-4_0_1\xercesSamples.jar;C:\dav4j_2_0_7\xml4j-4_0_1\xmlParserAPIs.jar
c:\dav4j_2_0_7\samples>javac -g GetProperties.java
GetProperties.java:6: package com.ibm.xml.parser does
not exist
import com.ibm.xml.parser.*;
^
GetProperties.java:56: cannot resolve symbol
symbol : class TXDocument
location: class GetProperties
TXDocument request = new TXDocument();
__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: getElementByTagName
Posted by Joseph Kesselman <ke...@us.ibm.com>.
Sounds like correct operation. You retreived the first child. The first
child is a Text node (eg whitespace/indentation) rather than an Element
node. Hence your attempt to cast it to Element fails. Same thing could
have happened if the first child was a comment.
If you want the first child element, loop through the children checking
node types until you find it (or fail to do so). THEN cast, if necessary.
______________________________________
Joe Kesselman / IBM Research
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: getElementByTagName
Posted by Sampath K Settipalli <Sa...@genome.wi.mit.edu>.
Hi Joseph & Mathias,
Thanks for the suggestions. Yeah its trying to cast TextNode since it is first
child . I tried (Element)nl.item(0); and seems to be working fine.
thanks,
Sampath
Mathias Laguerie wrote:
> Hi,
>
> I think you XML doc is similar than
> ...
>
> <header>
> <yourHeaderTag>
> .... etc
>
> so when you execute your code
> nl.item(0) return header tag
> nl.item(0).getFirstChild() return the textNode between header tag
> and yourHeaderTag
> And you try to cast this Text node in Element node. You can't do it
>
> if you want the header tag you can try this
> (Element)nl.item(0);
>
> If you want yourHeaderTag you have few solution. this is one
>
> Element header =
> (Element)(((Element)nl.item(0)).getElementsByTagName("yourHeaderTag").item(0))
> Mathias
>
> At 12:02 04/09/02 -0400, you wrote:
> >Hi ,
> >
> > In the process of migrating from xml4j to Xerces I'm replacing
> >classes/interfaces from xml4j with that of from xerces.
> >For TXElement headel = TXElement.getElementNamed("Header") ;
> >I replaced with these two lines NodeList nl =
> >root.getElementsByTagName("Header"); //roor it DocumentElement
> > Element headel = (Element)nl.item(0).getFirstChild();
> >
> >When I tried this at runtime it gives Exception in thread "main"
> >java.lang.ClassCastException: org.apache.xerces.dom.DeferredTextImpl at
> >this line
> >The xml document has a Element named Header with attributes in it & I
> >need to get the attributes . headel.getAttribute(Test");
> >How can get this work OR
> >Is there any better way to get Element with a tagName from a
> >DocumentElement and get attributes from it ?
> >
> >Thanks in advance,
> >Sampath
> >
> >
> >---------------------------------------------------------------------
> >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
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: getElementByTagName
Posted by Mathias Laguerie <ma...@softeam.fr>.
Hi,
I think you XML doc is similar than
...
<header>
<yourHeaderTag>
.... etc
so when you execute your code
nl.item(0) return header tag
nl.item(0).getFirstChild() return the textNode between header tag
and yourHeaderTag
And you try to cast this Text node in Element node. You can't do it
if you want the header tag you can try this
(Element)nl.item(0);
If you want yourHeaderTag you have few solution. this is one
Element header =
(Element)(((Element)nl.item(0)).getElementsByTagName("yourHeaderTag").item(0))
Mathias
At 12:02 04/09/02 -0400, you wrote:
>Hi ,
>
> In the process of migrating from xml4j to Xerces I'm replacing
>classes/interfaces from xml4j with that of from xerces.
>For TXElement headel = TXElement.getElementNamed("Header") ;
>I replaced with these two lines NodeList nl =
>root.getElementsByTagName("Header"); //roor it DocumentElement
> Element headel = (Element)nl.item(0).getFirstChild();
>
>When I tried this at runtime it gives Exception in thread "main"
>java.lang.ClassCastException: org.apache.xerces.dom.DeferredTextImpl at
>this line
>The xml document has a Element named Header with attributes in it & I
>need to get the attributes . headel.getAttribute(Test");
>How can get this work OR
>Is there any better way to get Element with a tagName from a
>DocumentElement and get attributes from it ?
>
>Thanks in advance,
>Sampath
>
>
>---------------------------------------------------------------------
>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