MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / asXml

Method asXml

src/main/java/org/htmlunit/html/DomNode.java:784–803  ·  view source on GitHub ↗

Returns a string representation as XML document from this element and all it's children (recursively). The charset used in the xml header is the current page encoding; but the result is still a string. You have to make sure to use the correct (in fact the same) encoding if you write this to a fi

()

Source from the content-addressed store, hash-verified

782 * @return the XML string
783 */
784 public String asXml() {
785 Charset charsetName = null;
786 final HtmlPage htmlPage = getHtmlPageOrNull();
787 if (htmlPage != null) {
788 charsetName = htmlPage.getCharset();
789 }
790
791 final StringWriter stringWriter = new StringWriter();
792 try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
793 boolean tag = false;
794 if (charsetName != null && this instanceof HtmlHtml) {
795 printWriter.print("<?xml version=\"1.0\" encoding=\"");
796 printWriter.print(charsetName);
797 printWriter.print("\"?>");
798 tag = true;
799 }
800 printXml("", tag, printWriter);
801 return stringWriter.toString();
802 }
803 }
804
805 /**
806 * Recursively writes the XML data for the node tree starting at <code>node</code>.

Callers 7

asXmlMethod · 0.95
serializeToStringMethod · 0.45
toXmlMethod · 0.45
toStringMethod · 0.45

Calls 5

getHtmlPageOrNullMethod · 0.95
getCharsetMethod · 0.95
printXmlMethod · 0.95
printMethod · 0.45
toStringMethod · 0.45

Tested by 1

asXmlMethod · 0.76