Example usage for org.xml.sax Attributes getLength

List of usage examples for org.xml.sax Attributes getLength

Introduction

In this page you can find the example usage for org.xml.sax Attributes getLength.

Prototype

public abstract int getLength();

Source Link

Document

Return the number of attributes in the list.

Usage

From source file:SAXTest.java

public static void main(String[] args) throws Exception {
    String url;/*from   ww w  . ja  v  a 2  s.co m*/
    if (args.length == 0) {
        url = "http://www.w3c.org";
        System.out.println("Using " + url);
    } else
        url = args[0];

    DefaultHandler handler = new DefaultHandler() {
        public void startElement(String namespaceURI, String lname, String qname, Attributes attrs) {
            if (lname.equals("a") && attrs != null) {
                for (int i = 0; i < attrs.getLength(); i++) {
                    String aname = attrs.getLocalName(i);
                    if (aname.equals("href"))
                        System.out.println(attrs.getValue(i));
                }
            }
        }
    };

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    SAXParser saxParser = factory.newSAXParser();
    InputStream in = new URL(url).openStream();
    saxParser.parse(in, handler);
}

From source file:Main.java

public static void DoConvertAttrsToStringMap(Attributes atts, HashMap<String, String> MapDest) {
    for (int attrsIndex = 0; attrsIndex < atts.getLength(); attrsIndex++) {
        String AttrName = atts.getLocalName(attrsIndex);
        String AttrValue = atts.getValue(attrsIndex);
        try {//w  w  w.j av  a 2  s . c o m
            AttrValue = URLDecoder.decode(AttrValue, URL_DECODE_TYPE);
            MapDest.put(AttrName, AttrValue);
        } catch (UnsupportedEncodingException e) {
            // TODO
        }

        //Log.w("FCXML", "DoConvertAttrsToStringMap: Index: " + attrsIndex + " Name: " + AttrName + " Value " + AttrValue );
    }
}

From source file:Main.java

public static Map<String, String> attributeToStringMap(Attributes attrs) {
    Map<String, String> data = new HashMap<String, String>();
    for (int i = 0; i < attrs.getLength(); i++) {
        data.put(attrs.getLocalName(i), attrs.getValue(i).trim());
    }/*from  ww w. j  av a 2  s  .  c  om*/
    return data;
}

From source file:com.bellman.bible.service.format.osistohtml.taghandler.TagHandlerHelper.java

public static void printAttributes(Attributes attrs) {
    for (int i = 0; i < attrs.getLength(); i++) {
        log.debug(attrs.getLocalName(i) + ":" + attrs.getValue(i));
    }//  w  w w . j a  va 2 s .  c  o m
}

From source file:Main.java

public static Map<String, String> toMap(Attributes attributes) {
    Map<String, String> nameToValue = new LinkedHashMap<String, String>();
    for (int i = 0; i < attributes.getLength(); i++) {
        nameToValue.put(attributes.getQName(i), attributes.getValue(i));
    }//from w w w .  j av  a  2 s.c  o  m
    return nameToValue;
}

From source file:io.wcm.handler.url.rewriter.impl.ComparableAttributes.java

static String serializedString(Attributes attributes) {
    StringBuilder serialized = new StringBuilder();
    for (int i = 0; i < attributes.getLength(); i++) {
        serialized.append(attributes.getLocalName(i)).append("=").append(attributes.getValue(i)).append(";");
    }/*from w  w w  .j  a v a2s .c o  m*/
    return serialized.toString();
}

From source file:Main.java

public static Map<String, String> convertSAXAttributes(Attributes attributes, boolean useQualifiedName) {
    Map<String, String> map = newAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        String key = useQualifiedName ? attributes.getQName(i) : attributes.getLocalName(i);
        String value = attributes.getValue(i);
        map.put(key, value);/* ww  w .  jav  a  2  s  . co  m*/
    }
    return map;
}

From source file:com.day.cq.wcm.foundation.TableXMLBuilder.java

private static void addAttributes(Table.Cell cell, Attributes attrs) {
    for (int i = 0; i < attrs.getLength(); i++) {
        String name = attrs.getLocalName(i);
        if (!name.equals("quotes")) {
            String value = attrs.getValue(i);
            cell.setAttribute(name, value);
        }// w w  w. j ava2s  .com
    }
}

From source file:com.day.cq.wcm.foundation.TableXMLBuilder.java

private static void addAttributes(Table.Tag tag, Attributes attrs) {
    for (int i = 0; i < attrs.getLength(); i++) {
        String name = attrs.getLocalName(i);
        if (!name.equals("quotes")) {
            String value = attrs.getValue(i);
            tag.setAttribute(name, value);
        }// w w  w.jav  a 2  s  .c om
    }
}

From source file:com.day.cq.wcm.foundation.TableXMLBuilder.java

private static void addAttributes(Table tag, Attributes attrs) {
    for (int i = 0; i < attrs.getLength(); i++) {
        String name = attrs.getLocalName(i);
        if (!name.equals("quotes")) {
            String value = attrs.getValue(i);
            tag.setAttribute(name, value);
        }//from   w ww.j a va 2  s  .  c om
    }
}