The Artima Developer Community
Sponsored Link

Java Answers Forum
HTMLEditorKit FORM tag disappears after read/write

1 reply on 1 page. Most recent reply: Feb 10, 2003 7:52 AM by Adam C. Graham

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
serg

Posts: 1
Nickname: serg
Registered: Jan, 2003

HTMLEditorKit FORM tag disappears after read/write Posted: Jan 10, 2003 6:55 AM
Reply to this message Reply
Advertisement
I'm using following code (output below):
After parsing and writing - HTML document looses <FORM> tags
Can anybody explain why it is happening and how to prevent it.

Thanks,

String readWriteDoc(String html)
{
System.out.println(html);
HTMLEditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();
String out_html="";

// The Document class does not yet handle charset's properly.
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
try {

// Create a reader on the HTML content.
Reader rd = new StringReader(html); // reads from a string

// Parse the HTML.
kit.read(rd, doc, 0);

// Iterate through the elements
// of the HTML document.
ElementIterator it = new ElementIterator(doc);
javax.swing.text.Element elem;
while ((elem = it.next()) != null)
{
dumpElementAttributes(elem);
}

Writer wr = new StringWriter();
kit.write(wr, doc, 0, doc.getLength());
out_html=wr.toString();

System.out.println(out_html);

} catch (Exception e) {
e.printStackTrace();
return "There was an error";
}
return out_html;
}


output:
......................................................... ...<body>
<script language="javaScript">
function IndexInputSubmit()
{
location.href = "http://localhost/test2.html";
return true;
}
</script>

TEST 1<br>
TEST 2<br>
TEST 3<br>
<a href=http://localhost/test2.html>test2.html</a>
<br>
<FORM action="member_login.jsp" method=POST>
<INPUT TYPE="SUBMIT" value="Go">
</FORM>
<p>
<FORM NAME="IndexInputForm" onSubmit="IndexInputSubmit(); return false;">
<INPUT TYPE="submit" VALUE="Go">
</FORM>

</body>
................................... .........................
name : html
function IndexInputSubmit() { location.href = "http://localhost/test2.html"; re
turn true; } TEST 1 TEST 2 TEST 3 test2.html
name : head
name : content
name : body
name : p-implied
function IndexInputSubmit() { location.href = "http://localhost/test2.h
tml"; return true; } TEST 1 TEST 2 TEST 3 test2.html
language : javaScript
name : script
f
name : content
function IndexInputSubmit() { location.href = "http://localhost/test2.ht
ml"; return true; }
endtag : true
name : script
name : content
name : br
name : content
name : br
name : content
name : br
a : href=http://localhost/test2.html
name : content
name : br
model : javax.swing.DefaultButtonModel@7a39ea
name : input
form : action=member_login.jsp method=post
value : Go
type : submit
name : content
name : p
model : javax.swing.DefaultButtonModel@7053be
name : input
form : name=IndexInputForm onsubmit=IndexInputSubmit(); return false;
value : Go
type : submit
name : content
name : p
name : content
............................................................
<html&g t;
<head>

</head>
<body>
<script language="javaScript">
function IndexInputSubmit() { location.href =
"http://localhost/test2.html"; return true; } </script> TEST 1<br>

TEST 2<br>TEST 3<br><a href="http://localhost/test2.html">test2.html</a><br><inp
ut value="Go" type="submit">


<p>
<input value="Go" type="submit">

</p>
</body>
</html>
..................... .......................................


Adam C. Graham

Posts: 1
Nickname: aleric
Registered: Feb, 2003

Re: HTMLEditorKit FORM tag disappears after read/write Posted: Feb 10, 2003 7:52 AM
Reply to this message Reply
The FORM tag is not kept. You may need to change the behaviour of HTMLDocument.HTMLReader:

:
:
registerTag (HTML.Tag.FORM, new MyFormAction ());

:
:

public class Form2Action extends CharacterAction
{
public void start (HTML.Tag t, MutableAttributeSet attr)
{
blockOpen (t, attr);
super.start (t, attr);
}


public void end (HTML.Tag t)
{
super.end (t);
blockClose (t);
}
}


Adam

Flat View: This topic has 1 reply on 1 page
Topic: yahoo games Previous Topic   Next Topic Topic: Errors please help!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use