Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * 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 printAttributes(XMLStreamReader xmlr, StringBuffer result) {
        for (int i = 0; i < xmlr.getAttributeCount(); i++) {
            printAttribute(xmlr, i, result);
        }
    }

    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);
    }
}