Here you can find the source of concatAttributes(List
attrName
for all elements in startElements
.
Parameter | Description |
---|---|
startElements | a parameter |
attrName | the name of the attribute whoose values to concatenate. |
attrName
for all elements in startElements
.
public static String concatAttributes(List<StartElement> startElements, QName attrName)
//package com.java2s; /*/* w w w .j ava 2 s . c o m*/ * Daisy Pipeline (C) 2005-2008 Daisy Consortium * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.Iterator; import java.util.List; import javax.xml.namespace.QName; import javax.xml.stream.events.Attribute; import javax.xml.stream.events.StartElement; public class Main { /** * Concatenates the value of the attribute named <code>attrName</code> * for all elements in <code>startElements</code>. * @param startElements * @param attrName the name of the attribute whoose values to * concatenate. * @return the value of the attribute named <code>attrName</code> * for all elements in <code>startElements</code>. */ public static String concatAttributes(List<StartElement> startElements, QName attrName) { String announcements = ""; for (int i = 0; i < startElements.size(); i++) { StartElement se = startElements.get(i); // jpritchett@rfbd.org: For some reason, the following doesn't work all the time. // Attribute at = se.getAttributeByName(attrName); // if (at != null) { // announcements += at.getValue() + " "; // } // Replaced with the following do-it-yourself iteration, 14 Aug 2006 for (Iterator<?> atIt = se.getAttributes(); atIt.hasNext();) { Attribute at = (Attribute) atIt.next(); if (attrName.equals(at.getName())) { announcements += at.getValue() + " "; break; } } } return announcements; } }