Example usage for org.xml.sax AttributeList getName

List of usage examples for org.xml.sax AttributeList getName

Introduction

In this page you can find the example usage for org.xml.sax AttributeList getName.

Prototype

public abstract String getName(int i);

Source Link

Document

Return the name of an attribute in this list (by position).

Usage

From source file:DocumentTracer.java

/** Start element. */
public void startElement(String name, AttributeList attributes) throws SAXException {

    printIndent();/*from  w w  w.j ava2  s  .co m*/
    fOut.print("startElement(");
    fOut.print("name=");
    printQuotedString(name);
    fOut.print(',');
    fOut.print("attributes=");
    if (attributes == null) {
        fOut.println("null");
    } else {
        fOut.print('{');
        int length = attributes.getLength();
        for (int i = 0; i < length; i++) {
            if (i > 0) {
                System.out.print(',');
            }
            String attrName = attributes.getName(i);
            String attrType = attributes.getType(i);
            String attrValue = attributes.getValue(i);
            fOut.print('{');
            fOut.print("name=");
            printQuotedString(attrName);
            fOut.print(',');
            fOut.print("type=");
            printQuotedString(attrType);
            fOut.print(',');
            fOut.print("value=");
            printQuotedString(attrValue);
            fOut.print('}');
        }
        fOut.print('}');
    }
    fOut.println(')');
    fOut.flush();
    fIndent++;

}

From source file:org.exolab.castor.xml.parsing.AttributeSetBuilder.java

/**
 * Processes the attributes and XML name space declarations found in the given SAX v1
 * AttributeList. The global AttributeSet is cleared and updated with the attribute data. XML name
 * space declarations are added to the set of XML name spaces in scope.
 * //w  ww  . j a v  a  2 s .c  o m
 * @deprecated
 * @param atts the {@link AttributeList} to process (can be null)
 **/
private AttributeSet processAttributeList(AttributeList atts, AttributeSetImpl attributeSet)
        throws SAXException {
    if (atts == null || atts.getLength() == 0)
        return attributeSet;

    // -- process all namespaces first
    int attCount = 0;
    boolean[] validAtts = new boolean[atts.getLength()];
    for (int i = 0; i < validAtts.length; i++) {
        String attName = atts.getName(i);
        if (attName.equals(XMLNS)) {
            _namespaceHandling.addDefaultNamespace(atts.getValue(i));
        } else if (attName.startsWith(XMLNS_PREFIX)) {
            String prefix = attName.substring(XMLNS_PREFIX_LENGTH);
            _namespaceHandling.addNamespace(prefix, atts.getValue(i));
        } else {
            validAtts[i] = true;
            ++attCount;
        }
    }
    // -- process validAtts...if any exist
    for (int i = 0; i < validAtts.length; i++) {
        if (!validAtts[i])
            continue;
        String namespace = null;
        String attName = atts.getName(i);
        int idx = attName.indexOf(':');
        if (idx > 0) {
            String prefix = attName.substring(0, idx);
            if (!prefix.equals(XML_PREFIX)) {
                attName = attName.substring(idx + 1);
                namespace = _namespaceHandling.getNamespaceURI(prefix);
                if (namespace == null) {
                    String error = "The namespace associated with " + "the prefix '" + prefix
                            + "' could not be resolved.";
                    throw new SAXException(error);

                }
            }
        }
        attributeSet.setAttribute(attName, atts.getValue(i), namespace);
    }
    return attributeSet;
}