I have a swing client that renders HTML through the use of the JEditorPane
and HTMLDocument
classes.
The problem I have is that I want to be able to define an area of the document as a container for some text that will be retrieved at a later date, and then use document.setInnerHTML(element, data);
to swap out the place-holder content with the "real" content.
So, I decided that I would define a tag similar to this:
<html>
<body>
some text <mytag id="1>placeholder</mytag> some more text
</body>
</html>
The problem occurs when I use document.getElement(String id)
- it finds mytag as an element, but it thinks it's a leaf element that has no content and so I cannot call .setInner() on it. Looking at it's parents list of elements, it thinks there are 3 - my tag has just been interpreted as individual components:
mytag (start)
content
mytag (end)
So, I'm guessing that I need to tell the document (or it's parser) about my tag, but that's where I'm falling flat as I'm fairly new to this area.
So, has anyone had any experience with this at all? I could cheat and use a span tag, but that doesn't feel right as (excluded for brevity) I also need to store an additional attribute against the tag.
Thanks in advance for your time...