Here you can find the source of getValue(Document doc, String Tag)
Parameter | Description |
---|---|
node | a parameter |
Tag | a parameter |
public static String getValue(Document doc, String Tag)
//package com.java2s; /****************************************************************************** * Product: OSeB http://code.google.com/p/oseb * * Copyright (C) 2012 Mario Grigioni * * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * * by the Free Software Foundation. This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along * * with this program; if not, write to the Free Software Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * *****************************************************************************/ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**//from w w w .jav a 2s . co m * Get Value from XML * * @param node * @param Tag * @return */ public static String getValue(Node node, String Tag) { if (node == null) return ""; NodeList nl = ((Element) node).getElementsByTagName(Tag); if (nl == null) return ""; Element el = (Element) nl.item(0); if (el == null) return ""; nl = el.getChildNodes(); if (nl == null) return ""; return nl.item(0).getNodeValue(); } /** * Get Value from XML * * @param node * @param Tag * @return */ public static String getValue(Document doc, String Tag) { if (doc.getElementsByTagName(Tag) == null) return ""; if (doc.getElementsByTagName(Tag).item(0) == null) return ""; return doc.getElementsByTagName(Tag).item(0).getTextContent(); } }