@Test public void nullSafeGetStringAttribute() throws XPathExpressionException { Node node = (Node) XPathFactory.newInstance().newXPath().evaluate("/test", doc, XPathConstants.NODE); assertEquals("stringValue", XMLUtils.nullSafeGetStringAttribute(node, "stringAttr")); assertNull(XMLUtils.nullSafeGetStringAttribute(node, "chuckNorris")); Node node2 = (Node) XPathFactory.newInstance().newXPath().evaluate("/chuckNorris", doc, XPathConstants.NODE); assertNull(node2); assertNull(XMLUtils.nullSafeGetStringAttribute(node2, "kick")); }
public static String nullSafeGetStringAttribute(Node node, String attributeName) { if (node != null) { Node namedItem = node.getAttributes().getNamedItem(attributeName); if (namedItem != null) { return namedItem.getNodeValue(); } } return null; }
XMLUtils { public static String nullSafeGetStringAttribute(Node node, String attributeName) { if (node != null) { Node namedItem = node.getAttributes().getNamedItem(attributeName); if (namedItem != null) { return namedItem.getNodeValue(); } } return null; } }
XMLUtils { public static String nullSafeGetStringAttribute(Node node, String attributeName) { if (node != null) { Node namedItem = node.getAttributes().getNamedItem(attributeName); if (namedItem != null) { return namedItem.getNodeValue(); } } return null; } private  XMLUtils(); }
XMLUtils { public static String nullSafeGetStringAttribute(Node node, String attributeName) { if (node != null) { Node namedItem = node.getAttributes().getNamedItem(attributeName); if (namedItem != null) { return namedItem.getNodeValue(); } } return null; } private  XMLUtils(); static String nullSafeGetStringAttribute(Node node, String attributeName); static boolean nullSafeGetBooleanAttribute(Node node, String attributeName); static boolean nullSafeGetBooleanAttribute(Node node, String attributeName, boolean defaultValue); }
XMLUtils { public static String nullSafeGetStringAttribute(Node node, String attributeName) { if (node != null) { Node namedItem = node.getAttributes().getNamedItem(attributeName); if (namedItem != null) { return namedItem.getNodeValue(); } } return null; } private  XMLUtils(); static String nullSafeGetStringAttribute(Node node, String attributeName); static boolean nullSafeGetBooleanAttribute(Node node, String attributeName); static boolean nullSafeGetBooleanAttribute(Node node, String attributeName, boolean defaultValue);  }