• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving HTML markup from swing componant

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am wondering if it is possible to extract the HTML markup from a swing object once it has been set and displayed on the object.

For example, I can set the content type on a swing textpane to text/html and then set the text to be a html table within code with the .setText() method. The textpane then has a nice rendered HTML table displayed.

From here I would like to do the reverse and obtain the HTML markup that produced the table. I am having trouble getting the raw markup text back. I can only manage to get the rendered text which is devoid of the original markup.

Does anyone know if this is possible?

Cheers, Jared.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't know of any way to get back the authentic html [perhaps a deep dump of the obj might reveal a secret cache], but - in theory - you should be able to reconstruct the meat of it by 'serializing' the Document obj. i'll explain.

as i understand it, java is able to do the rendering you are describing via model and view classes. the view is what gets rendered, the model is the nodal representation of the underlying html parse tree.

to make a long story short, i would try traversing "the structural portion of the subject that this view is mapped to" (ie. the document)

From the document root node (Element), you can traverse all the elements and attributes and 'serialize it' back to html.

there are classes to help with the serialization somewhere in javax.xml or org.xml .. you would use the relevant html dtd (or something simpler) for the schema.

i hope someone else can suggest a shorter way to do it...

hth
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic