List of utility methods to do XML Element Get
Element | getElementDescendant(Element elem, String ns_uri, String tagName) get Element Descendant NodeList nl = elem.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if ((node.getNamespaceURI() == null || node.getNamespaceURI().equals(ns_uri)) && node.getLocalName().equals(tagName)) { return (Element) node; } else { ... |
Element | getElementForLine(Document document, int line) get Element For Line Element[] roots = document.getRootElements();
Element root = roots[0];
return root.getElement(line - 1);
|
String | getElementId(Element element) get Element Id return element.getAttribute("id"); |
int | getElementIndex(Element ele) Returns the index of the Node within the current sub-tree. int index = 1; Node prev = ele.getPreviousSibling(); while (prev != null) { if (prev.getNodeType() == Node.ELEMENT_NODE) { if (((Element) prev).getNodeName().equals(ele.getNodeName())) { ++index; prev = prev.getPreviousSibling(); return index; |
int | getElementIndex(Element element) Returns the index of element in the list of all elements with the same name in its parent node. int index = 1; Node sibling = element; while ((sibling = sibling.getPreviousSibling()) != null) { if (sibling instanceof Element) { Element siblingElement = (Element) sibling; if (element.getLocalName().equals(siblingElement.getLocalName()) && (element.getNamespaceURI() == null ? siblingElement.getNamespaceURI() == null : element.getNamespaceURI().equals(siblingElement.getNamespaceURI()))) { ... |
String | getElementLanguage(Element elemNode, String defaultLangCode) Returns the language code associated with the specified element. String langCode = defaultLangCode; if (elemNode.hasAttribute(langAttName)) { langCode = elemNode.getAttribute(langAttName); } else if (elemNode.hasAttributeNS("xml", "lang")) { langCode = elemNode.getAttributeNS("xml", "lang"); return langCode; |
String | getElementLanguage(Element elemNode, String defaultLangCode) Returns the language code associated with the specified element. String langCode = defaultLangCode; if (elemNode.hasAttribute("language")) { langCode = elemNode.getAttribute("language"); } else if (elemNode.hasAttribute("lang")) { langCode = elemNode.getAttribute("lang"); } else if (elemNode.hasAttributeNS("xml", "lang")) { langCode = elemNode.getAttributeNS("xml", "lang"); return langCode; |
List | getElementList(Document doc, String expression) get Element List XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPath = xPathFactory.newXPath(); XPathExpression expr = xPath.compile(expression); NodeList nodeList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); List<Element> elementList = new ArrayList<Element>(); for (int i = 0; i < nodeList.getLength(); i++) { Node item = nodeList.item(i); if (item instanceof Element) { ... |
List | getElementList(Element dataRoot, String name) get Element List NodeList list = dataRoot.getElementsByTagName(name); List<Element> listElements = new ArrayList<Element>(); for (int i = 0; i < list.getLength(); i++) { listElements.add((Element) list.item(i)); return listElements; |
List | getElementList(Element dataRoot, String name) get Element List NodeList list = dataRoot.getElementsByTagName(name); List<Element> listElements = new ArrayList<Element>(); for (int i = 0; i < list.getLength(); i++) { Element item = (Element) list.item(i); if (item.getParentNode().equals(dataRoot)) { listElements.add(item); return listElements; |