Java XML Attribute Print printAttributes(XMLStreamReader xmlr)

Here you can find the source of printAttributes(XMLStreamReader xmlr)

Description

Print out element attributes

License

Open Source License

Parameter

Parameter Description
xmlr Stream reader

Declaration

public static void printAttributes(XMLStreamReader xmlr) 

Method Source Code

//package com.java2s;
/*//  w  ww .  j  a  v  a2  s  .  com
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2004-2011 Oracle and/or its affiliates. All rights reserved.
 *
 * Oracle licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.xml.stream.XMLStreamReader;
import javax.xml.namespace.QName;

public class Main {
    /** Print out element attributes
     *
     * @param xmlr Stream reader
     */
    public static void printAttributes(XMLStreamReader xmlr) {
        if (xmlr.getAttributeCount() > 0) {
            System.out.println("\nHAS ATTRIBUTES: ");
            int count = xmlr.getAttributeCount();
            for (int i = 0; i < count; i++) {

                QName name = xmlr.getAttributeName(i);
                String namespace = xmlr.getAttributeNamespace(i);
                String type = xmlr.getAttributeType(i);
                String prefix = xmlr.getAttributePrefix(i);
                String value = xmlr.getAttributeValue(i);

                System.out.println("ATTRIBUTE-PREFIX: " + prefix);
                System.out.println("ATTRIBUTE-NAMESP: " + namespace);
                System.out.println("ATTRIBUTE-NAME:   " + name.toString());
                System.out.println("ATTRIBUTE-VALUE:  " + value);
                System.out.println("ATTRIBUTE-TYPE:  " + type);
                System.out.println();

            }

        } else {
            System.out.println("HAS NO ATTRIBUTES");
        }
    }
}

Related

  1. printAttribute(String nombre, NodeList nodes)
  2. printAttribute(String nombre, NodeList nodes)
  3. printAttribute(XMLStreamReader xmlr, int index, StringBuffer result)
  4. printAttributes(Element element)
  5. printAttributes(NamedNodeMap attributes, String indent, boolean descend)
  6. printAttributesCompact(NamedNodeMap attributes, String indent, boolean descend)
  7. printAttrs(Element elem, String endient, PrintStream pstrm)
  8. printImageAttributeType(Integer value)