Java Utililty Methods XML Format

List of utility methods to do XML Format

Description

The list of methods to do XML Format are organized into topic(s).

Method

voidprint(Node node, Writer out, boolean omitdecl)
write this as an XML document in a stream
try {
    if (node == null)
        return;
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    transformer.setOutputProperty("omit-xml-declaration", (omitdecl ? "yes" : "no"));
    DOMSource source = new DOMSource(node);
    StreamResult result = new StreamResult(out);
...
voidprint(SOAPMessage msg, OutputStream out)
print
StreamResult result = new StreamResult(out);
print(msg, result);
StringprintAttributeValue(Element node, String prefix)
Print SAML Attribute Element and replace its prefix with the input prefix.
if (node == null) {
    return null;
StringBuffer xml = new StringBuffer(100);
xml.append('<');
xml.append(prefix).append(node.getLocalName());
NamedNodeMap attrs = node.getAttributes();
int length = attrs.getLength();
...
voidprintNode(Node n)
Print the specified XML DOM node to System.out
printNode(n, System.out);
voidprintNode(Node node)
print Node
try {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    StringWriter sw = new StringWriter();
...
voidprintNode(Node node, String fn)
print Node
try {
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer;
    transformer = tFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    DOMSource source = new DOMSource(node);
    PrintStream out = System.out;
...
voidprintNode(OutputStream out, Node node, boolean prettyPrint, boolean includeXmlDeclaration)
print Node
try {
    Transformer serializer = tFactory.newTransformer();
    if (prettyPrint) {
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    if (!includeXmlDeclaration) {
        serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
...
voidprintNodeSubtreeXMLString(final Node node)
print Node Subtree XML String
writeNodeSubtreeXMLString(node, new PrintWriter(System.out));
voidprintNodeToConsole(Node n, ByteArrayOutputStream byteArrayOS)
print Node To Console
try {
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    Properties oform = new Properties();
    oform.setProperty("encoding", "ISO-8859-1");
    transformer.setOutputProperties(oform);
    transformer.transform(new DOMSource(n), new StreamResult(byteArrayOS));
} catch (Exception e) {
...
voidprintReply(SOAPMessage reply)
print reply to output to System.out
System.out.println("Reply:");
SOAPPart sp = reply.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPBody body = envelope.getBody();
Iterator itBody = body.getChildElements();
while (itBody.hasNext()) {
    SOAPElement element = (SOAPElement) itBody.next();
    printElement(element);
...