Skip to content

Commit

Permalink
a bit more docu
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Aug 4, 2024
1 parent 338b6e5 commit 961130a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/htmlunit/html/DomNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,10 @@ public String getVisibleText() {
}

/**
* Returns a string representation of the XML document from this element and all it's children (recursively).
* The charset used is the current page encoding.
* Returns a string representation as XML document from this element and all it's children (recursively).
* The charset used is the current page encoding.<br>
* This serializes the current state of the DomTree - this implies that the content of noscript tags
* usually serialized as string because the content is converted during parsing (if js was enabled at that time).
* @return the XML string
*/
public String asXml() {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/htmlunit/html/HtmlPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,30 @@ public void asXml_unicode() throws Exception {
assertTrue(xml.contains(unicodeString));
}

/**
* @throws Exception if the test fails
*/
@Test
public void asXml_noscript() throws Exception {
final String html = "<html>"
+ "<body>"
+ "<noscript><p><strong>your browser does not support JavaScript</strong></p></noscript>"
+ "</body></html>";

final String expected = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
+ "<html>"
+ " <head/>"
+ " <body>"
+ " <noscript>"
+ " &lt;p&gt;&lt;strong&gt;your browser does not support JavaScript&lt;/strong&gt;&lt;/p&gt;"
+ " </noscript>"
+ " </body>"
+ "</html>";

final HtmlPage page = loadPage(html);
assertEquals(expected, page.asXml().replaceAll("[\\n\\r]", ""));
}

/**
* @exception Exception if the test fails
*/
Expand Down

0 comments on commit 961130a

Please sign in to comment.