Java XML Attribute Print printAttribute(XMLStreamReader xmlr, int index, StringBuffer result)

Here you can find the source of printAttribute(XMLStreamReader xmlr, int index, StringBuffer result)

Description

print Attribute

License

LGPL

Declaration

private static void printAttribute(XMLStreamReader xmlr, int index, StringBuffer result) 

Method Source Code

//package com.java2s;
/*/*w ww  . j ava 2  s  .com*/
 * Copyright LGPL3
 * YES Technology Association
 * http://yestech.org
 *
 * http://www.opensource.org/licenses/lgpl-3.0.html
 */

import javax.xml.stream.XMLStreamReader;

public class Main {
    private static void printAttribute(XMLStreamReader xmlr, int index, StringBuffer result) {
        String prefix = xmlr.getAttributePrefix(index);
        String namespace = xmlr.getAttributeNamespace(index);
        String localName = xmlr.getAttributeLocalName(index);
        String value = xmlr.getAttributeValue(index);
        result.append(" ");
        printName(prefix, namespace, localName, result);
        result.append("='").append(value).append("'");
    }

    private static void printName(XMLStreamReader xmlr, StringBuffer result) {
        if (xmlr.hasName()) {
            String prefix = xmlr.getPrefix();
            String uri = xmlr.getNamespaceURI();
            String localName = xmlr.getLocalName();
            printName(prefix, uri, localName, result);
        }
    }

    private static void printName(String prefix, String uri, String localName, StringBuffer result) {
        if (uri != null && !("".equals(uri)))
            result.append("['").append(uri).append("']:");
        if (prefix != null)
            result.append(prefix).append(":");
        if (localName != null)
            result.append(localName);
    }
}

Related

  1. printAttribute(Node node, int level)
  2. printAttribute(String nombre, NodeList nodes)
  3. printAttribute(String nombre, NodeList nodes)
  4. printAttributes(Element element)
  5. printAttributes(NamedNodeMap attributes, String indent, boolean descend)
  6. printAttributes(XMLStreamReader xmlr)
  7. printAttributesCompact(NamedNodeMap attributes, String indent, boolean descend)