public static String getCharacterDataFromElement(Element e) { Node child = e.getFirstChild(); if (child instanceof CharacterData) { CharacterData cd = (CharacterData) child; return cd.getData(); } return "?"; }
private String getCharacterDataFromElement(Element e) { try { Node child = e.getFirstChild(); if (child instanceof CharacterData) { CharacterData cd = (CharacterData) child; return cd.getData(); } } catch (Exception ignored) { } return ""; }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node nameNode; CharacterData child; String childData; doc = (Document) load("staff", true); elementList = doc.getElementsByTagName("address"); nameNode = elementList.item(0); child = (CharacterData) nameNode.getFirstChild(); child.deleteData(0, 16); childData = child.getData(); assertEquals("characterdataDeleteDataBeginingAssert", "Dallas, Texas 98551", childData); }