List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:com.wavemaker.tools.ws.XJCCompiler.java
private static Element removeImportElement(Element element) { NodeList nodeList = element.getElementsByTagNameNS(Constants.XSD_NS, "import"); if (nodeList.getLength() == 0) { return element; // simply returns the original one }/*from w w w. jav a2s .c o m*/ // do a clone since we are going to remove the import stuffs from the // element Element elementClone = (Element) element.cloneNode(true); nodeList = elementClone.getElementsByTagNameNS(Constants.XSD_NS, "import"); List<Node> ns = new ArrayList<Node>(); for (int tmp = 0; tmp < nodeList.getLength(); tmp++) { Node importNode = nodeList.item(tmp); ns.add(importNode); } for (Node item : ns) { Node schemaNode = item.getParentNode(); schemaNode.removeChild(item); } return elementClone; }
From source file:Main.java
/** * Searches through an entire sub-tree for child Elements whose QName * matches the one given. The results are not guaranteed to be in any * particular order, and are <b>not</b> limited to direct children of * the given context node. <br>/*w w w . j a v a 2 s .com*/ * <br> * If you want to limit your search for Elements to the direct children * of a given Element, use the getAllElement, getElement, and getElements * methods. Those guarantee that all results are directly beneath the * given context. * * @param context * The root node from which the search will be done. * @param qname * The QName of the Element to search for. * @return An array with all occurrences of child Elements with the * given name. The Elements may be anywhere in the sub-tree, * meaning they may not be direct children of the context node. * The only guarantee is that they are somewhere beneath the * context node. The method returns an empty array if no * occurrences are found. * @see Element#getElementsByTagNameNS(String, String) * @see #getAllElements(Node) * @see #getElement(Node, QName) * @see #getElements(Node, QName) */ public static Element[] findInSubTree(final Element context, final QName qname) { final String name = qname.getLocalPart(); final String uri = qname.getNamespaceURI(); // // DOM's getElementsByTagName methods search the whole subtree // final NodeList matches = context.getElementsByTagNameNS(uri, name); final int length = matches.getLength(); final Element[] asArray = new Element[length]; for (int n = 0; n < length; ++n) asArray[n] = (Element) matches.item(n); return asArray; }
From source file:ee.ria.xroad.opmonitordaemon.QueryRequestHandlerTest.java
@SneakyThrows private static String findRecordsContentId(SoapMessage message) { Element response = (Element) message.getSoap().getSOAPBody() .getElementsByTagNameNS(OM_NS, OPERATIONAL_DATA_RESPONSE).item(0); return response.getElementsByTagNameNS(OM_NS, RECORDS).item(0).getTextContent(); }
From source file:Main.java
/** * Wrapper for <code>getElementsByTagName</code> with the "quirk" that it * returns an array instead of a "live" NodeList (meaning that changes to * the DOM tree after returning the element list will not affect the element * list)./*from w ww . jav a 2 s .co m*/ * * @param parent * @param decendantElementsNS * @param decentantElementsName * @return */ public static List<Element> getNamedDecendants(Element parent, String decendantElementsNS, String... decentantElementsNames) { List<Element> res = new ArrayList<Element>(); for (String decentantElementsName : decentantElementsNames) { NodeList elements = null; if (decendantElementsNS != null && decendantElementsNS.length() > 0) { elements = parent.getElementsByTagNameNS(decendantElementsNS, decentantElementsName); } else { elements = parent.getElementsByTagName(decentantElementsName); } for (int i = 0; i < elements.getLength(); i++) { res.add((Element) elements.item(i)); } } return res; }
From source file:com.nortal.jroad.util.SOAPUtil.java
/** * Returns child elements according to name and namespace * // w w w . j a v a2 s . co m * @param root * @param name * @param ns * @return */ public static NodeList getNsElements(Element root, String name, String ns) { if (root == null) { return null; } return root.getElementsByTagNameNS(ns, name); }
From source file:Main.java
public static Element firstChildElement(Element element, String childNameSpace, String childName) throws NoSuchElementException { NodeList childCandidateList;// ww w . j a v a 2 s.c om if (childNameSpace == null || childNameSpace.isEmpty()) { childCandidateList = element.getElementsByTagName(childName); } else { /*childCandidateList = element.getElementsByTagNameNS(childNameSpace, childName);*/ childCandidateList = element.getElementsByTagNameNS(childNameSpace, childName); } if (childCandidateList.getLength() > 0) { Element firstChild = (Element) childCandidateList.item(0); return firstChild; } else { throw new NoSuchElementException("No child candidate found in this element"); } }
From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java
public static Boolean hasQueryDefinitionTag(XmlValueType xml) { Element rootElement = xml.getAny().get(0); NodeList gtElements = rootElement.getElementsByTagNameNS("*", "query_definition"); if (gtElements.getLength() == 0) return false; else/*from w w w.ja va 2 s . c o m*/ return true; }
From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java
public static Boolean hasObservationTag(XmlValueType xml) { Element rootElement = xml.getAny().get(0); NodeList gtElements = rootElement.getElementsByTagNameNS("*", "observation_set"); if (gtElements.getLength() == 0) return false; else/*from ww w .ja v a 2 s.c o m*/ return true; }
From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java
public static Boolean hasPatientDataTag(XmlValueType xml) { Element rootElement = xml.getAny().get(0); NodeList gtElements = rootElement.getElementsByTagNameNS("*", "patient_data"); if (gtElements.getLength() == 0) return false; else/* w w w . j a v a 2 s . c o m*/ return true; }
From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java
public static Boolean hasPatientTag(XmlValueType xml) { Element rootElement = xml.getAny().get(0); NodeList gtElements = rootElement.getElementsByTagNameNS("*", "patient_set"); if (gtElements.getLength() == 0) return false; else/*from w ww.jav a 2 s . co m*/ return true; }