Example usage for org.xml.sax AttributeList getValue

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

Introduction

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

Prototype

public abstract String getValue(String name);

Source Link

Document

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

Usage

From source file:SAXDemo.java

public void startElement(String name, AttributeList attributes) {
    accumulator.setLength(0); // Ready to accumulate new text
    // If its a servlet tag, look for id attribute
    if (name.equals("servlet"))
        servletId = attributes.getValue("id");
}

From source file:DocumentTracer.java

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

    printIndent();//w  ww  . ja va2s. 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.
 * /*from  www.java  2 s  .co  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;
}