+ /**
+ * Gets the result of the HTTP method as an XHTML document.
+ * @param aMethod Method to invoke.
+ * @return XHTML as a byte array.
+ * @throws URIException In case of poblems with the URI
+ * @throws IOException In case of problems obtaining the XHTML.
+ */
+ private byte[] getXhtml(HttpMethod aMethod) throws URIException, IOException {
+ // Transform the HTML into wellformed XML.
+ Tidy tidy = new Tidy();
+ tidy.setXHTML(true);
+ tidy.setQuiet(true);
+ tidy.setShowWarnings(false);
+ if (_os != null) {
+ _os.println("Content of '" + aMethod.getURI() + "'");
+ _os.println();
+ }
+ // We write the jtidy output to XML since the DOM tree it produces is
+ // not namespace aware and namespace awareness is required by XSLT.
+ // An alternative is to configure namespace awareness of the XML parser
+ // in a system wide way.
+ Document w3cDoc = tidy.parseDOM(aMethod.getResponseBodyAsStream(),
+ _os);
+ DOMUtility.removeDuplicateAttributes(w3cDoc);
+
+ ByteArrayOutputStream xhtml = new ByteArrayOutputStream();
+ XMLSerializer serializer = new XMLSerializer(xhtml, new OutputFormat());
+ serializer.serialize(w3cDoc);
+ xhtml.flush();
+ if (_os != null) {
+ _os.println();
+ }
+ return xhtml.toByteArray();
+ }
+