Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:33:06+00:00 2026-05-25T12:33:06+00:00

I am looking for XML/XHTML Java library/framework that can perform the following two tasks

  • 0

I am looking for XML/XHTML Java library/framework that can perform the following two tasks for me.

Before going on few definitions:

  • NodeOffset(Node node, int offset) marks some point in text node in the XML tree.
  • nodeB, nodeI, nodeP are the corresponding Node instances of the below mentioned XHTML tree and nodeSpan is some newly created node (where Node is not necessarily org.w3c.dom.Node and may be any other abstraction)

Flattering XHTML into plain text

The library should be able to produce plaintext output (e.g. by implementing CharSequence or similar) from given XHTML and provide one-to-one mapping between chars in the output and original XHTML node tree (e.g. via the function NodeOffset getNodeOffset(int plainTextOffset)).

Example: Suppose we have the following XHTML:

<p><b>GeForce</b> 9300M GS provides powerful <i>visual computing features</i> to thin and light notebooks.</p>

Then the plaintext representation will obviously be:

GeForce 9300M GS provides powerful visual computing features to thin and light notebooks.

Then e.g.

  • getNodeOffset(0) should return node NodeOffset(nodeB, 0)
  • getNodeOffset(40) should return node NodeOffset(nodeI, 5)
  • getNodeOffset(80) should return node NodeOffset(nodeP, 49).

I might miss the correct numbers, but I hope, you got the idea. I repeat the example, now with pseudo-markers inserted:

|GeForce 9300M GS provides powerful visua|l computing features to thin and light n|otebooks.

and

<p><b>|GeForce</b> 9300M GS provides powerful <i>visua|l computing features</i> to thin and light n|otebooks.</p>

Node manipulating

The library should provide a possibility to inject nodes into XHTML, that may span the tree possibly crossing the node boundaries e.g. via the operation NodeSet insert(Node nodeToInsert, NodeOffset start, NodeOffset end, int mode). The function works in two modes:

  • mode1: Split the node to be inserted if necessary. In this case the splitted from nodeToInsert nodes are returned as operations result.
  • mode2: Close the parent nodes. nodeToInsert is returned as is.

For example: the insert(nodeSpan, NodeOffset(nodeB, 2), NodeOffset(nodeP, 9), mode1) operation should produce

<p><b>Ge<span>Force</span></b><span> 9300M GS</span> provides powerful <i>visual computing features</i> to thin and light notebooks.</p>

insert(nodeSpan, NodeOffset(nodeB, 2), NodeOffset(nodeP, 9), mode2) operation should produce:

<p><b>Ge</b><span><b>Force</b> 9300M GS</span> provides powerful <i>visual computing features</i> to thin and light notebooks.</p>

It is analogue to what users do in rich editor:

GeForce 9300M GS

I wonder, if there is anything like this in OpenSource world, as I really don’t want to re-implement the wheel… I’ve checked quickly Open Source HTML Parsers in Java without success.

When you post an answer:

  • Make sure the above mentioned functions are available in library API (provide a link to JavaDoc).
  • The library is Java-native (no JNI) and OpenSource.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:33:07+00:00Added an answer on May 25, 2026 at 12:33 pm

    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
    |-<p >
    | |-<b >
    | | |-Text: GeForce
    | |-Text:  9300M GS provides powerful 
    | |-<i >
    | | |-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
    |-<p >
    | |-<b >
    | | |-Text: GeFo
    | | |-Text: rce
    | |-Text:  9300M GS provides powerful 
    | |-<i >
    | | |-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.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found a few posts alluding to the fact that you can validate XHTML
I'm looking for an XML parser that instead of parsing from an InputStream or
I've been looking around the System.Xml namespace, but don't see anything that would support
I'm looking for the best method to parse various XML documents using a Java
Consider the following css and html. <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I'm reading an xml file generated by a 3rd-party application that includes the following:
I’m looking for XML Diff class or library. There are my requirements: - open
I have an XML document looking similar to this: <items> <item cat=1 owner=14>bla</item> <item
As stated in the title, i'm looking for an XML schema (XSD-file) for the
Looking to nest (to unlimited levels) elements in XML. Like so: <items> <item> <name>Item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.