Displaying xml in textarea without rendering htmlentities - java

I've been reading about this for a while now and can't find the solution.
This looks like the solution I need:
How to stop html textarea from interpreting html entities into their characters
But when I do this I just get in the textarea. What gives?
This is my first time trying to use jstl. Please help.

use jquery's text() method and assign it to text area.

Related

How would you parse this String to an object?

Note that this question is not about implementation, but for programming tips.
I'm trying to read some HTML code, and then create an object / several objects in order to paint it back again chaning the format.
For example. Imagine this html:
<body>
Hello, this is some plain and I'm going to attach an image.
<img src="someimage.jpg" />
And after the image I keep writting.
And as this is a forum message, you can add a div to quote like the following:
<div class="post-quote"> Some user said something</div>
And that was it!
</body>
As you can see, there are several elements, like <img> and <div>.
My overall goal, is to have everything split up like:
Text
Image
Text
Div(quote class)
Text
And then, programming specific, it could be a List of contentElements.
With this list, I could paint those elements back into the screen customly formatted and positioned.
However, I can't find out how to divide the HTML String using some logical method.
Do you guys have any tips? How would you split this String to achieve the previously explained issue?
Thanks!!
Questions are welcome!
Edit
JSOUP is a parser. I'm not looking for a parser. I'm looking for TIPS about how can I keep the order of the parsed elements. Reread my question, please!
You should use a HTML parser such as jsoup.
Example on your HTML:
Document doc = Jsoup.parse(html);
print(doc.select("img").attr("src")); ==> someimage.jpg
print(doc.select("div.post-quote").text()); ==> Some user said something

Is it possible to add a superscript to a superscript in a JLabel´s html?

I need to show the function eAxn inside a JLabel, but trying to do so doesn't work and only shows as eAxn which is confusing. eAx^n could help, but that's not what I'm looking for.
Probably is because of the html version, or JLabels just dislike nested superscripts.
How else would you approach this for a JLabel?
For that specific case there exists a special-2 \u00b2.
<html>e<sup>0.5x²</sup>
The HTML editor kit, and styled text uses character attributes, which probably prevent nesting of <sup> tags. Maybe with <span style='...'> something can be done too.

Formatting Text

I need to format some text in JOptionPane.showMessageDialog. I need the text to be in tabular format
Example:
Operation Result
2 + 2 4
I have tried to use string.format() but it comes out ugly. Any suggestions would be helpful. Thanks
String.format would work well if you were using a fixed-width font (like a console output) but the message dialogs default to a variable-width font.
Luckily all labels in Swing support HTML formatting. All you have to do is wrap your string with HTML tags like <html> some text</html>. Then you could use an actual HTML table.
It seems like you got some number of data to be displayed. Using JDialog instead of JOptionpane is better to put number of data. Answer to your question can be found in the below link
http://forums.techguy.org/software-development/1051819-solved-help-java-tabular-format.html
You can pass a String containing the data in html code, you can try to do this format with a HTML table.

Convert html code into plain text

I am developing android application in which i want to convert html code in to plain text and display it in the editText. I use Jsoup.jar for that but it shrink the data. Like it just remove the tag.I will not got to the next line. Does any one has the solution to display html code in the plain text? Any help or suggestions are accepted. Thank you.
Use Html.fromHtml(htmltext).

Problem With HTML display in JEditorPane java

Im trying to display html in a JEditorPane. Initially the type is set to "text/html".
When I use setPage(URL) it works fine and the resulting output is displayed but If I have a String that contains HTML code and I used setText(String) to display the result on the JEditorPane nothing is displayed I see only white space.
Of-course if I copied the whats in the string pasted it in notpad, saved it as .html then opened the resulting file in the browser it displayed correctly. The real problem is in how or what the JEditorPane does with the string inorder to display whats inside it. The JEditorPane is inside a JscrollPane which is inside a Jframe. and I only used setContentType( "text/html" ) and setText(String) methods for html display.
Is there anyway to get around this than wrting the resulting html code to a file and using SetPage(URL)? I can post the html code if you need it (but its quite large). Thanks for your help.
Don't know why setText does not work. But here is a workaround.
Try this URL. (the whole file in the URL) (This is what Android's WebView calls when you setText in it)
data:text/html;charset=utf-8,%3C%21DOCTYPE%20html%3E%0D%0A%3Chtml%20lang%3D%22en%22%3E%0D%0A%3Chead%3E%3Ctitle%3EEmbedded%20Window%3C%2Ftitle%3E%3C%2Fhead%3E%0D%0A%3Cbody%3E%3Ch1%3E42%3C%2Fh1%3E%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A%0D%0A
It starts with data:text/html;charset=utf-8, and is followed by your HTML.
However you do have to encode it.. At least you have to replace % with %25 The rest might just work without encoding though.
You can also use this code to embed images without calling a file
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC" />
You just have to base64 encode your image and then you can paste it right in.

Categories

Resources