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

  • Home
  • SEARCH
  • 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 6660863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:12:30+00:00 2026-05-26T02:12:30+00:00

I have (still) problems with HTMLEditorKit and HTMLDocument in Java. I can only set

  • 0

I have (still) problems with HTMLEditorKit and HTMLDocument in Java. I can only set the inner HTML of an element, but I cannot get it. Is there some way, how to get a uderlying HTML code of an element?

My problem is, that the HTML support is quite poor and bad written. The API does not allow basic and expected functions. I need change the colspan or rowspan attribute of <td>. The Java developers have closed the straightforward way: the attribute set of element is immutable. The workaround could be to take the code of element (e.g. <td colspan="2">Hi <u>world</u></td>) and replace it with new content (e.g. <td colspan="3">Hi <u>world</u></td>). This way seems to be closed too. (Bonus question: What’s the HTMLEditorKit good for?)

  • 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-26T02:12:30+00:00Added an answer on May 26, 2026 at 2:12 am

    Thanks for hint, Stanislav. That’s my solution:

    /**
     * The method gets inner HTML of given element. If the element is named <code>p-implied</code>
     * or <code>content</code>, it returns null.
     * @param e element
     * @param d document containing given element
     * @return the inner HTML of a HTML tag or null, if e is not a valid HTML tag
     * @throws IOException
     * @throws BadLocationException
     */
    public String getInnerHtmlOfTag(Element e, Document d) throws IOException, BadLocationException {
        if (e.getName().equals("p-implied") || e.getName().equals("content"))
            return null;
    
        CharArrayWriter caw = new CharArrayWriter();
        int i;
        final String startTag = "<" + e.getName();
        final String endTag = "</" + e.getName() + ">";
        final int startTagLength = startTag.length();
        final int endTagLength = endTag.length();
    
        write(caw, d, e.getStartOffset(), e.getEndOffset() - e.getStartOffset());
        //we have the element but wrapped as full standalone HTML code beginning with HTML start tag
        //thus we need unpack our element
        StringBuffer str = new StringBuffer(caw.toString());
        while (str.length() >= startTagLength) {
            if (str.charAt(0) != '<')
                str.deleteCharAt(0);
            else if (!str.substring(0, startTagLength).equals(startTag))
                str.delete(0, startTagLength);
            else
                break;
        }
        //we've found the beginning of the tag
        for (i = 0; i < str.length(); i++) { //skip it...
            if (str.charAt(i) == '>')
                break; //we've found end position of our start tag
        }
        str.delete(0, i + 1); //...and eat it
        //skip the content
        for (i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '<' && i + endTagLength < str.length() && str.substring(i, i + endTagLength).equals(endTag))
                break; //we've found the end position of inner HTML of our tag
        }
        str.delete(i, str.length()); //now just remove all from i position to the end
    
        return str.toString().trim();
    }
    

    This method can be easilly modified to get outter HTML (so the code containing the entire tag).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two basic Cpp tasks, but still I have problems with them. First
I've updated active_admin to version 0.3.0 to get internationalization working. But I have problems
I'm having problems with creating mySQL table within Java program. I constantly get Can't
I still have some problems with jQuery. If I have html like this: <form
So I have been intrigued by the ?? operator, but have still been unable
I installed jOOQ into eclipse, generated classes for my mySQL, but I still have
Very new to PHP5 and have some problems still. I figured out how to
I'm starting with linqToSql and I still have some problems making my queries. For
I have tried following how-set-up-your-own-private-git-server-linux and private-remote-git-repositories-ubuntu-linode but I am still having problems. My
I have installed latest version of Node.js and I still have problems with SSL

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.