Adam
Adam

Reputation: 277

Java XML Node Edit without Node.getTextContents()

I'm using an old version of the JRE (1.4) where Node.getTextContents() and Node.setTextContents() are not available. Is there a long way to do these actions still?

Example XML:

<MyEle>4119<MyEle/>

Java:

//myEleNode is a Node found while traversing
String nodeString = myEleNode.getTextContent();
if(nodeString.equals("4119")){//do something}

Upvotes: 1

Views: 1754

Answers (2)

Bogdan
Bogdan

Reputation: 1150

You will have to iterate over the children, check if their type is text (node.getNodeType() == Node.TEXT_NODE) and then get the text value using node.getNodeValue().

Upvotes: 1

DMKing
DMKing

Reputation: 1715

The text is a child node of the MyEle element, so you would use something like:

MyEle.getFirstChild().getNodeValue()

Upvotes: 3

Related Questions