List of usage examples for org.w3c.dom Element hasAttribute
public boolean hasAttribute(String name);
true
when an attribute with a given name is specified on this element or has a default value, false
otherwise. From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/* www . j a v a 2 s . com*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); boolean has = element.hasAttribute("value"); String attrValue = element.getAttribute("value"); element.setAttribute("value", "newValue1"); element = doc.getElementById("key2"); has = element.hasAttribute("value"); attrValue = element.getAttribute("value"); element.setAttribute("value", "a<\"'&>z"); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w ww . j a v a 2 s. c o m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); element.setAttribute("newAttrName", "attrValue"); element.setAttribute("newAttrName", "<>&\"'"); element.removeAttribute("value"); boolean has = element.hasAttribute("value"); // true String attrValue = element.getAttribute("value"); // mydefault }
From source file:Main.java
/** * @param topicRef// ww w. j ava 2s . c o m * @return */ public static boolean isMapReference(Element topicRef) { return (topicRef.hasAttribute("href") && topicRef.hasAttribute("format") && topicRef.getAttribute("format").equals("ditamap")); }
From source file:Main.java
public static String getAttr(Element e, String attr) { if (e.hasAttribute(attr)) { return e.getAttribute(attr); }/*from www . ja v a 2 s .co m*/ return null; }
From source file:Main.java
public static boolean attributeBoolValue(Element e, String attr) { if (!e.hasAttribute(attr)) return false; String val = e.getAttribute(attr); return val.equals("yes") || val.equals("true") || val.equals("1"); }
From source file:Main.java
public static boolean isAttributeTrue(Element elem, String attribute) { return elem.hasAttribute(attribute) && "true".equals(elem.getAttribute(attribute)); }
From source file:Main.java
public static String getAttributeValue(Element current, String attrName) { return current.hasAttribute(attrName) ? current.getAttribute(attrName) : null; }
From source file:Main.java
/** * Returns true if the topicref specifies format="ditamap" * @param topicref/*from ww w .j a v a 2 s .c o m*/ * @return */ public static boolean targetIsADitaMap(Element topicref) { if (topicref.hasAttribute(DITA_FORMAT_ATTNAME)) { String formatValue = topicref.getAttribute(DITA_FORMAT_ATTNAME); if ("ditamap".equalsIgnoreCase(formatValue)) return true; } return false; }
From source file:Main.java
/** * Return true if the linking element specifies a, explcitly or implicitly, a * DITA map or topic document.//from w w w .j a v a 2 s .c om * @param link An element that may exhibit the format attribute * @return */ public static boolean targetIsADitaFormat(Element link) { if (link.hasAttribute(DITA_FORMAT_ATTNAME)) { String formatValue = link.getAttribute(DITA_FORMAT_ATTNAME); if (!DITA_ELEM_TAGNAME.equalsIgnoreCase(formatValue) && !"ditamap".equalsIgnoreCase(formatValue)) return false; } return true; // default format is "dita" }
From source file:Main.java
public static String getAttribute(Element elem, String name, String def) { return elem.hasAttribute(name) ? elem.getAttribute(name) : def; }