XHTML manipulation library in Java?

I wrapped code that I had already, with modifications to match your requests (WIP) in an open-source project: ShtutXML It's pretty documented, so I doubt you'll have a problem using it.

I wrapped code that I had already, with modifications to match your requests (WIP) in an open-source project: ShtutXML. It's pretty documented, so I doubt you'll have a problem using it. The first request (Finding a node and offsets from a global position) is already built in, and splitting of text nodes in the XML is already built in (so you can easily wrap them in new nodes as you wish).

Therefore, adding the logic for marking areas with an element is rather trivial. I'll try to do it later, but this is my best effort on this request for now. On your XML, using my example program this is my output: ************* BASE DOCUMENT ***************** DOCUMENT ROOT |- | |- | | |-Text: GeForce | |-Text: 9300M GS provides powerful | |- | | |-Text: visual computing features | |-Text: to thin and light notebooks.

*** Text *** "GeForce 9300M GS provides powerful visual computing features to thin and light notebooks. " *** Node of each text segment *** b: null: GeForce p: null: 9300M GS provides powerful i: null: visual computing features p: null: to thin and light notebooks. *** Offset testing *** offset 0 is at b: null at 0 offset 40 is at i: null at 5 offset 80 is at p: null at 48 Asking it to split the element at the global position 4 will produce *********** Split(4) DOCUMENT ***************** DOCUMENT ROOT |- | |- | | |-Text: GeFo | | |-Text: rce | |-Text: 9300M GS provides powerful | |- | | |-Text: visual computing features | |-Text: to thin and light notebooks.

*** Node of each text segment *** b: null: GeFo b: null: rce p: null: 9300M GS provides powerful i: null: visual computing features p: null: to thin and light notebooks. Of course this syntactical split means nothing for the actual XML code that matches that document, but it will allow wrapping one text part at a time with any other node you wish. Edit: The first insertion mode is already supported Edit 2: The second insertion mode is already supported Notes: Any document modification you may do, will make all the offsetts invalid.

Using them later will cause corruption of the entire document. So, after each modification you must do GetOffset to retreive the offsetts again. I know some of the functions are not documented.

Basically the only functions that should be used outside of the package are the ones you requested from the StrXML class. More documentation will be added later and you can contact me by email (see my profile page) for questions.

Maybe you could try jsoup - jsoup.org. It is an open source Java library distributed under the MIT license. Its source code is available at GitHub.

From the home page: jsoup is a Java library for working with real-world HTML. It provides a very convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods. With jsoup you can: find and extract data, using DOM traversal or CSS selectors manipulate the HTML elements, attributes, and text Here is its Javadoc: jsoup.org/apidocs.

I've had good success using jsoup on projects that had similar functionality needs in the past. – cdeszaq Sep 9 '11 at 13:50 @Luc1245: Are you sure that jsoup provides the functionality which I need (please, provide a link to the class, that does it), or your answer is only a guess? On later case your answer does not deserve a bounty, sorry.

– dma_k Sep 10 '11 at 12:09 Well, it's easy to retrieve (or set) the whole plain text of any element using the text() method of the org.jsoup.nodes. Element class; but while studying the API docs to post a demo I couldn't find implementations of the other functionalities you require. So now I'm working on another answer – Luc125 Sep 10 '11 at 19:05 @Luc1245: The major problem is not to "planify" XML, but also to map from resulting string back to XML tree.

See the examples I have provided in my question (do you see any getNodeByTextOffset()? ). Also for "planification" for simple case you need only a trivial XSLT transformation.

– dma_k Sep 12 '11 at 8:49.

I tried Jericho couple of years back it it was deceptively simple to use its API for parsing. I used it for logging into yahoo mail and fetching the contacts from the address book. I sure it can do much more than.

The home page mentions one of your requirement "Flattering XHTML into plain text" as one of its features. Some of the features which might be relevant to your questions are Built-in functionality to extract all text from HTML markup The begin and end positions in the source document of all parsed segments are accessible, allowing modification of only selected segments of the document without having to reconstruct the entire document from a tree. And its Free open source.(Quoting the site :You are therefore free to use it in commercial applications subject to the terms detailed in either one of these licence documents.

).

The same as for other answers: I see the Renderer API which allows to convert XML to plaintext. But where is the reverse mapping? – dma_k Sep 12 '11 at 8:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions