getTextContent alternative

R

rohit

IF anybody can throw some light on following issue:
Hi,

Operating System : Mac OS X 10.3.9
Java version: 1.4.2


I have an application that uses getTextContent(), setTextContent()
which are not present in JDK 1.4.2 so
I am in process of adding/using JAXP 1.3.2 on JDK 1.4.2.


Below are the steps I tried for the same but still couldnot resolve the

issue :


1. Downloaded JAXP 1.3.2 from
https://jaxp.dev.java.net/files/documents/913/28792/JAXP_RI_20060217....

and unpacked the same using java -cp . JAXP_RI_20060217


(There is another step written in the URL to compile using jDK.1.4.2
with source/target = 1.4, i couldnot get that point so omiited for the
time being)


2. Placed the files dom.jar, jaxp-api.jar, sax.jar, xalan.jar,
xerecsImpl.jar at following path:


/Systems/Library/Frameworks/JavaVM.framework/Version/1.4.2/Home/lib/endrose­d.



3. And recompiled the project. Using JBuilder 2005 for building the
application.


But still the application couldnot get the functions, getTextContent
and setTextContent


As per my understanding the application is not able to connect to these

jar.


Do we need to explicitly specify the path of these jars ??


I hope similiar issue might have been faced earlier too ??


What can be the possible solution?


Regards,
RDH
 
O

Oliver Wong

rohit said:
Operating System : Mac OS X 10.3.9 [...]
2. Placed the files dom.jar, jaxp-api.jar, sax.jar, xalan.jar,
xerecsImpl.jar at following path:

/Systems/Library/Frameworks/JavaVM.framework/Version/1.4.2/Home/lib/endrose­d.

3. And recompiled the project. Using JBuilder 2005 for building the
application.

But still the application couldnot get the functions, getTextContent
and setTextContent

As per my understanding the application is not able to connect to these
jar.

Do we need to explicitly specify the path of these jars ??

If the problem is that the application can't find the JAR, try adding
those JARs to your build path. Hopefully JBuilder 2005 has an option for
configuring the buildpath.

But the problem might be that no classes in those JARs actually define
the getTextContent() and setTextContent() methods. Did you check the
documentation for those JARs to check if they do define those methods?

- Oliver
 
R

rohit

Yes, these API are exposed. I have found other alternative but donot
know how correct is it

node.getFirstChild().getNodeValue()

Will the above serve same as getTextContent() ?
Rohit
 
O

Oliver Wong

rohit said:
Yes, these API are exposed. I have found other alternative but donot
know how correct is it

node.getFirstChild().getNodeValue()

Will the above serve same as getTextContent() ?

I don't know. Read the documentation and see if they do the same thing.

I'm guessing maybe you're doing something to do with XML, but I can't
tell for sure from the context I have available to me.

If this is XML-stuff (i.e. you're working with the w3c.dom package), I
think the two methods don't do the same thing. If node is an attribute, then
getFirstChild() will return null, thus leading to a NullPointerException,
for example.

- Oliver
 
T

the_schmitz

I'm running into the same problem. I've tried putting the JARs in my
Classpath and the endorsed directory, and still no luck. Were you able
to find a solution to the problem, besides upgrading to version 1.5 of
the JDK?

Thanks
 
Joined
Oct 30, 2007
Messages
1
Reaction score
0
SDK 1.4 implementation of getTextContent

rohit said:
Hi,
I have a java application using JDK 1.5 and now need to run the same
application on JDK 1.4. I have used a function "getTextContent()" that
is available in JDK 1.5 and above

org.w3c.dom.Node nChildlist;
nChildlist.getTextContent() // works fine on JDK 1.5 but gives
following error in JDK 1.4

cannot find symbol method getTextContent()

Has anybody encountered similar situation ?
What is the possible workaround for the same ?
Any solution for the same is welcome

Thanks ,
RDH

The code below has worked for me with succes.

/**
* Recursive implementation of the method
* org.w3c.dom.Node.getTextContent which is present
* in JDK 1.5 but not 1.4
* @author Tobias Hinnerup ([email protected])
* @param node
* @return
*/
private String getTextContent(Node node) {
Node child;
String sContent = node.getNodeValue() != null ? node.getNodeValue() : "";

NodeList nodes = node.getChildNodes();
for(int i = 0; i < nodes.getLength(); i++) {
child = nodes.item(i);
sContent += child.getNodeValue() != null ? child.getNodeValue() : "";
if(nodes.item(i).getChildNodes().getLength() > 0) {
sContent += getTextContent(nodes.item(i));
}
}

return sContent;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top