Skip to main content

Help with html tags in java

1 reply [Last post]
peliukasss
Offline
Joined: 2010-02-02
Points: 0

Hello,

I'm writing a program and I have a problem. I want to read text between html tags. eg:
Some text .
Any idea how to do this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jtp51
Offline
Joined: 2003-10-25
Points: 0

You could use javax.xml.parsers.DocumentBuilder. From the API, [i]"An instance of this class can be obtained from the DocumentBuilderFactory.newDocumentBuilder()"[/i].

Then parse out a new DOM Document object - Document is an Interface.

Next I would get an Element type object, then a NodeList type object, in which you want to end up with a Node.

The Node type object contains several methods to extract or manipulate the text between tags. http://java.sun.com/javase/6/docs/api/org/w3c/dom/Node.html