/** * Detects if some content starts with the standard XML prefix. * * @param target the content to check * @return true if the document starts with the standard XML prefix. */ public static boolean isXML(byte [] target){ return startsWith(target, XML_PFX,0); }
private void showRenderXMLResponse(SampleResult res) { results.setContentType("text/xml"); // $NON-NLS-1$ results.setCaretPosition(0); byte[] source = res.getResponseData(); final ByteArrayInputStream baIS = new ByteArrayInputStream(source); for (int i = 0; i < source.length - XML_PFX.length; i++) { if (JOrphanUtils.startsWith(source, XML_PFX, i)) { baIS.skip(i);// NOSONAR Skip the leading bytes (if any) break; } } StringWriter sw = new StringWriter(); Tidy tidy = XPathUtil.makeTidyParser(true, true, true, sw); org.w3c.dom.Document document = tidy.parseDOM(baIS, null); document.normalize(); if (tidy.getParseErrors() > 0) { showErrorMessageDialog( sw.toString(), "Tidy: " + tidy.getParseErrors() + " errors, " + tidy.getParseWarnings() + " warnings", JOptionPane.WARNING_MESSAGE); } JPanel domTreePanel = new DOMTreePanel(document); new ExpandPopupMenu().add(domTreePanel); resultsScrollPane.setViewportView(domTreePanel); }