Java XML QName concatAttributes(List startElements, QName attrName)

Here you can find the source of concatAttributes(List startElements, QName attrName)

Description

Concatenates the value of the attribute named attrName for all elements in startElements.

License

Open Source License

Parameter

Parameter Description
startElements a parameter
attrName the name of the attribute whoose values to concatenate.

Return

the value of the attribute named attrName for all elements in startElements.

Declaration

public static String concatAttributes(List<StartElement> startElements,
        QName attrName) 

Method Source Code

//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;
    }
}

Related

  1. addNamespace(Element element, QName qName)
  2. addTypeQname(QName elemntNameSpace, List propertyQnameValueList, PropertyDescriptor propDesc, QName beanName, boolean processingDocLitBare)
  3. compareQName(QName qname, Node node)
  4. compareRelation(QName a, QName b)
  5. compareWithOutNamespace(QName value, QName tagName)
  6. contains(final QName[] qnames, final QName qname, final String defaultNamespace)
  7. convertQNameListToNamespaceToLocalNameList( List list)
  8. convertQNameToFullname(QName qn)
  9. convertToQName(String source, String nameSpaceuri)

  10. HOME | Copyright © www.java2s.com 2016