Code example for Element

Methods: getFirstChild

0
import org.xml.sax.SAXException; 
 
public abstract class XmlUtilities { 
 
	public static String getCharacterDataFromElement(Element e) {
	    Node child = e.getFirstChild();
	    if (child instanceof CharacterData) {
	      CharacterData cd = (CharacterData) child;
	      return cd.getData();
	    } 
	    return ""; 
	} 
	 
	public static Document parseXmlStringToDocument(String xmlString) throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xmlString));
        return db.parse(is);
	} 
}