Here you can find the source of addChildEpcList(final Document document, final Element root, final String childEPCs)
Parameter | Description |
---|---|
document | The Document to generate the <epc> and <childEPCs> element from. |
root | The root Element under which the <childEPCs> element should be generated. |
childEPCs | A space-separated list of EPCs. |
false
otherwise.
public static boolean addChildEpcList(final Document document, final Element root, final String childEPCs)
//package com.java2s; /*/*from w ww . j a va 2s. c o m*/ * Copyright (C) 2007 ETH Zurich * * This file is part of Fosstrak (www.fosstrak.org). * * Fosstrak is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * Fosstrak 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 Fosstrak; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ import java.util.StringTokenizer; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /** * Adds the EPCs from the given list of childEPCs as {@code <epc>} elements * inside an {@code <childEPCs>} element to the XML document. * * @param document * The Document to generate the {@code <epc>} and {@code * <childEPCs>} element from. * @param root * The root Element under which the {@code <childEPCs>} element * should be generated. * @param childEPCs * A space-separated list of EPCs. * @return <true> if the {@code <childEPCs>} element was successfully * created, <code>false</code> otherwise. */ public static boolean addChildEpcList(final Document document, final Element root, final String childEPCs) { if (isEmpty(childEPCs)) { return false; } Element element = document.createElement("childEPCs"); StringTokenizer st = new StringTokenizer(childEPCs); while (st.hasMoreTokens()) { addElement(document, element, st.nextToken(), "epc"); } root.appendChild(element); return true; } private static boolean isEmpty(String s) { return s == null || s.trim().equals(""); } private static boolean addElement(final Document document, final Element root, final String elementValue, final String elementName) { if (isEmpty(elementValue)) { return false; } Element element = document.createElement(elementName); element.appendChild(document.createTextNode(elementValue)); root.appendChild(element); return true; } }