Get the xml string of the XML object. @return The XML data as a string
()
| 542 | * @return The XML data as a string |
| 543 | */ |
| 544 | public String toString() { |
| 545 | String str; |
| 546 | try { |
| 547 | TransformerFactory transFactory = TransformerFactory.newInstance(); |
| 548 | transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD,""); |
| 549 | transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,""); |
| 550 | Transformer transformer = transFactory.newTransformer(); |
| 551 | StringWriter buffer = new StringWriter(); |
| 552 | transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,"yes"); |
| 553 | transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); |
| 554 | transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
| 555 | transformer.setOutputProperty |
| 556 | ("{http://xml.apache.org/xslt}indent-amount", "4"); |
| 557 | Element root = ownerDoc.getDocumentElement(); |
| 558 | transformer.transform(new DOMSource(root), new StreamResult(buffer)); |
| 559 | str = buffer.toString(); |
| 560 | } catch (TransformerException ex) { |
| 561 | str = "Could not transform: Transformer exception"; |
| 562 | } |
| 563 | return str; |
| 564 | } |
| 565 | } |