Java XML Attribute Print printAttrs(Element elem, String endient, PrintStream pstrm)

Here you can find the source of printAttrs(Element elem, String endient, PrintStream pstrm)

Description

print Attrs

License

Open Source License

Declaration

static private void printAttrs(Element elem, String endient,
            PrintStream pstrm) 

Method Source Code

//package com.java2s;
/*  it under the terms of the GNU General Public License as published by    */

import org.w3c.dom.Element;

import org.w3c.dom.Attr;

import org.w3c.dom.NamedNodeMap;

import java.io.PrintStream;

public class Main {
    static private final String ELEM_ENDIENT = "\t";

    static private void printAttrs(Element elem, String endient,
            PrintStream pstrm) {/*from   w w w.j  a  v  a  2  s  .c o  m*/
        NamedNodeMap attrs = elem.getAttributes();

        if (attrs.getLength() == 0) {
            pstrm.print(">");
            return;
        }

        Attr attr = (Attr) attrs.item(0);

        if (attrs.getLength() == 1) {
            pstrm.print(" " + attr.getName() + "=\"" + attr.getValue()
                    + "\">");
            return;
        }

        endient += ELEM_ENDIENT;

        for (int i = 0; i < attrs.getLength(); i++) {
            attr = (Attr) attrs.item(i);
            pstrm.print("\n" + endient + attr.getName() + "=\""
                    + attr.getValue() + "\"");
        }

        pstrm.print(">");
    }
}

Related

  1. printAttribute(XMLStreamReader xmlr, int index, StringBuffer result)
  2. printAttributes(Element element)
  3. printAttributes(NamedNodeMap attributes, String indent, boolean descend)
  4. printAttributes(XMLStreamReader xmlr)
  5. printAttributesCompact(NamedNodeMap attributes, String indent, boolean descend)
  6. printImageAttributeType(Integer value)