List of usage examples for org.xml.sax Attributes getLength
public abstract int getLength();
From source file:Main.java
/** The opening tag of an element. */ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { System.out.println("-" + locator.getLineNumber() + "---Opening tag of an element"); System.out.println(" Namespace: " + namespaceURI); System.out.println(" Local name: " + localName); System.out.println(" Qualified name: " + qName); for (int i = 0; i < atts.getLength(); i++) { System.out.println(" Attribute: " + atts.getQName(i) + "=\"" + atts.getValue(i) + "\""); }// w w w .j a v a2 s. c om }
From source file:com.mapr.xml2json.MySaxParser.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); JSONObject tag = new JSONObject(); JSONArray array = new JSONArray(); int length = attributes.getLength(); for (int i = 0; i < length; i++) { JSONObject temp = new JSONObject(); String qNameVal = attributes.getQName(i); String valueVal = attributes.getValue(i); if (qNameVal != null) qNameVal = cleanQName(qNameVal); if (valueVal.trim().length() > 0) { tag.put(qNameVal, valueVal); //array.add(temp); }// www. j ava 2 s.com } if (array.size() > 0) tag.put("attributes", array); // tag.put("qName",cleanQName(qName)); //log.info("After clean:" + cleanQName(qName)); stk.push(tag); }
From source file:net.sf.joost.emitter.DOMEmitter.java
/** * SAX2-Callback - Creates a DOM-element-node and memorizes it for the * {@link #endElement(String ,String ,String)} method by putting it onto the * top of this stack./*from www . j ava 2s .c o m*/ */ public void startElement(String uri, String local, String raw, Attributes attrs) throws SAXException { // create new element : iterate over all attribute-values Element elem = document.createElementNS(uri, raw); int nattrs = attrs.getLength(); for (int i = 0; i < nattrs; i++) { String namespaceuri = attrs.getURI(i); String value = attrs.getValue(i); String qName = attrs.getQName(i); if ((namespaceuri == null) || (namespaceuri.equals(""))) { elem.setAttribute(qName, value); } else { elem.setAttributeNS(namespaceuri, qName, value); } } // append this new node onto current stack node insertNode(elem); // push this node into the global stack stack.push(elem); }
From source file:ezbake.thrift.utils.xml2thrift.sax.StringHandler.java
/** * This is an inherited SAX method. The handler extends it to parse XML. *///w w w . j av a 2 s . c om public void startElement(String uri, String localName, String qName, Attributes attributes) { if (qName.equalsIgnoreCase(root)) { sbEntry.setLength(0); inRootItem = true; } if (inRootItem) { sbEntry.append("<" + qName + ">"); /* Populate the attributes to the XML string */ for (int i = 0; i < attributes.getLength(); i++) { sbEntry.append("<" + attributes.getQName(i) + ">"); sbEntry.append(attributes.getValue(i)); sbEntry.append("</" + attributes.getQName(i) + ">"); } } }
From source file:com.icesoft.faces.webapp.parser.ComponentRuleSet.java
private Attributes clone(Attributes attributes) { Attributes clone = new AttributesImpl(attributes); for (int i = 0; i < clone.getLength(); i++) { String name = attributes.getQName(i); String value = attributes.getValue(name); ((AttributesImpl) clone).setLocalName(i, name); ((AttributesImpl) clone).setValue(i, value); }//from ww w.j av a 2 s . c om return clone; }
From source file:com.ibm.jaql.lang.expr.xml.XmlToJsonFn.java
@Override public void startElement(String uri, String localName, String name, Attributes attrs) throws SAXException { try {/* w w w . jav a 2 s . co m*/ SpilledJsonArray ca = new SpilledJsonArray(); int n = attrs.getLength(); for (int i = 0; i < n; i++) { name = "@" + attrs.getLocalName(i); uri = attrs.getURI(i); String v = attrs.getValue(i); BufferedJsonRecord r = new BufferedJsonRecord(); if (uri != null && uri.length() > 0) { r.add(S_XMLNS, new JsonString(uri)); } r.add(new JsonString(name), new JsonString(v)); ca.addCopy(r); } stack.push(ca); } catch (IOException e) { throw new UndeclaredThrowableException(e); } }
From source file:com.icesoft.faces.webapp.parser.ComponentRuleSet.java
/** * Create clone of attributes.// w w w .java2 s . c o m * * @param attributes Attributes to clone. * @return Cloned attributes. */ private Attributes clone(Attributes attributes) { Attributes clone = new AttributesImpl(attributes); for (int i = 0; i < clone.getLength(); i++) { String name = attributes.getQName(i); String value = attributes.getValue(name); ((AttributesImpl) clone).setLocalName(i, name); ((AttributesImpl) clone).setValue(i, value); } return clone; }
From source file:at.yawk.fanfiction.api.web.ChapterHandler.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { switch (stage) { case BEFORE:/*w ww . jav a 2 s . c om*/ if (qName.equals("div") && "storytext".equals(attributes.getValue("id"))) { stage = TEXT; textBuilder = new StringBuilder(); } break; case TEXT: textBuilder.append('<').append(qName); for (int i = 0; i < attributes.getLength(); i++) { textBuilder.append(" "); textBuilder.append(attributes.getQName(i)); textBuilder.append("=\""); textBuilder.append(attributes.getValue(i).replace("\\", "\\\\").replace("\"", "\\\"")); textBuilder.append("\""); } textBuilder.append('>'); break; } }
From source file:fulcrum.xml.Parser.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { textBuilder.setLength(0);/*from ww w.j a v a 2 s . c om*/ Element c = new Element(qName, uri); xPathBuilder.append(FORWARD_SLASH).append(localName); addXPath(xPathBuilder.toString(), c); for (int i = 0; i < attributes.getLength(); i++) { Attribute a = new Attribute(attributes.getQName(i), attributes.getURI(i), attributes.getValue(i)); addXPath(xPathBuilder.toString() + AT + a.getLocalName(), a); c.addAttribute(a); } elements.push(c); }
From source file:com.netspective.commons.xml.AbstractContentHandler.java
public String getAttributeNames(Attributes attributes) { StringBuffer sb = new StringBuffer(" Attrs: ["); for (int i = 0; i < attributes.getLength(); i++) { sb.append(attributes.getQName(i)); sb.append("="); sb.append(attributes.getValue(i)); sb.append(" "); }//ww w .j a v a 2s . co m sb.append(attributes); sb.append("]"); return sb.toString(); }