List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:com.evolveum.midpoint.util.QNameUtil.java
public static QName getNodeQName(Node node) { return new QName(node.getNamespaceURI(), node.getLocalName()); }
From source file:Main.java
/** * This method searches children of Element element for element with tagName * and namespaceURI nsName. It searchs one level down only. * /* w w w . ja v a 2s . c om*/ * @param element * The root element * @param nsName * NamespaceURI * @param tagName * A String representing the name of the tag to be searched for. * @return A List of elements that meet the criterial. */ public static List getElementsByTagNameNS1(Element element, String nsName, String tagName) { List list = new ArrayList(); if (element != null) { NodeList nl = element.getChildNodes(); int length = nl.getLength(); Node child = null; String childName; String childNS; for (int i = 0; i < length; i++) { child = nl.item(i); childName = child.getLocalName(); childNS = child.getNamespaceURI(); if ((childName != null) && (childName.equals(tagName)) && (childNS != null) && (childNS.equals(nsName))) { list.add(child); } } } return list; }
From source file:Main.java
private static Node convertFromNamespaceForm(final Node node) { if (node instanceof Element) { final Document document = node.getOwnerDocument(); final Element newElement = document.createElementNS(null, node.getLocalName()); final NodeList children = node.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { final Node oldChildNode = children.item(i); final Node newChildNode = convertFromNamespaceForm(oldChildNode); newElement.appendChild(newChildNode); }/*from w ww . j av a2 s. co m*/ final NamedNodeMap attributes = node.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { final Attr attr = (Attr) attributes.item(i); final String attrQualifiedName = attr.getNodeName(); final String attrLocalName = attr.getLocalName(); if (!attrQualifiedName.equals(XMLNS) && !attrQualifiedName.startsWith(XMLNS_COLON) && !attrLocalName.equals(XSI_SCHEMA_LOCATION_ATTR)) { newElement.setAttributeNS(null, attrLocalName, attr.getValue()); } } return newElement; } else { return node.cloneNode(true); } }
From source file:Main.java
/** * This method searches children of Element element for element with tagName * and namespaceURI nsName. It searchs one level down only. * @param element The root element/*from ww w. j a va2 s. c o m*/ * @param nsName NamespaceURI * @param tagName A String representing the name of the tag to be searched * for. * @return A List of elements that meet the criterial. */ @SuppressWarnings("unchecked") public static List getElementsByTagNameNS1(Element element, String nsName, String tagName) { List list = new ArrayList(); if (element != null) { NodeList nl = element.getChildNodes(); int length = nl.getLength(); Node child = null; String childName; String childNS; for (int i = 0; i < length; i++) { child = nl.item(i); childName = child.getLocalName(); childNS = child.getNamespaceURI(); if ((childName != null) && (childName.equals(tagName)) && (childNS != null) && (childNS.equals(nsName))) { list.add(child); } } } return list; }
From source file:com.weibo.wesync.notify.xml.DomUtils.java
/** Matches the given node's name and local name against the given desired names. */ private static boolean nodeNameMatch(Node node, Collection desiredNames) { return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName())); }
From source file:Main.java
/** * Access an immediate child element inside the given Element * * @param element the starting element, cannot be null. * @param namespaceURI name space of the child element to look for, * cannot be null. Use "*" to match all namespaces. * @param elemName the name of the child element to look for, cannot be * null./* www . j a v a 2s. c o m*/ * @return the first immediate child element inside element, or * <code>null</code> if the child element is not found. */ public static Element getChildElement(Element element, String namespaceURI, String elemName) { NodeList list = element.getChildNodes(); int len = list.getLength(); for (int i = 0; i < len; i++) { Node n = list.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (elemName.equals(n.getLocalName()) && ("*".equals(namespaceURI) || namespaceURI.equals(n.getNamespaceURI()))) { return (Element) n; } } } return null; }
From source file:Main.java
/** * @param sibling/* w w w . j a v a 2s . co m*/ * @param uri * @param nodeName * @return nodes with the constrain */ public static Element[] selectNodes(Node sibling, String uri, String nodeName) { int size = 20; Element[] a = new Element[size]; int curr = 0; //List list=new ArrayList(); while (sibling != null) { if (nodeName.equals(sibling.getLocalName()) && uri.equals(sibling.getNamespaceURI())) { a[curr++] = (Element) sibling; if (size <= curr) { int cursize = size << 2; Element[] cp = new Element[cursize]; System.arraycopy(a, 0, cp, 0, size); a = cp; size = cursize; } } sibling = sibling.getNextSibling(); } Element[] af = new Element[curr]; System.arraycopy(a, 0, af, 0, curr); return af; }
From source file:edu.duke.cabig.c3pr.webservice.integration.XMLUtils.java
/** * Does deep comparison of two DOM trees represented by the given * {@link Element}s. Elements are considered root nodes of the trees. <br> * <br>// w w w. ja v a2 s .c om * This version of the method will <b>only</b> process elements of types * {@link Node#ELEMENT_NODE},{@link Node#TEXT_NODE}, * {@link Node#CDATA_SECTION_NODE}; others will be ignored. Content of text * nodes is normalized before comparison. <br> * <br> * When comparing two elements, their local names, namespaces, and * attributes (except <code>xmlns* and xsi:type</code>) are accounted for. <br> * <br> * Due to issues with using * <code>setIgnoringElementContentWhitespace(true)</code>, which does not * seem to work, this method will throw out empty text nodes when comparing * children. * * @since 1.0 * @param e1 * @param e2 * @return */ public static boolean isDeepEqual(Node n1, Node n2) { if (!StringUtils.equals(n1.getLocalName(), n2.getLocalName())) { log.info("Node local names are not equal: " + n1.getLocalName() + " " + n2.getLocalName()); return false; } if (!StringUtils.equals(n1.getNamespaceURI(), n2.getNamespaceURI())) { log.info("Node namespaces are not equal: " + n1.getNamespaceURI() + " " + n2.getNamespaceURI()); return false; } if (n1.getNodeType() != n2.getNodeType()) { log.info("Node types are not equal: " + n1.getNodeType() + " " + n2.getNodeType()); return false; } // check attributes equality. NamedNodeMap attrs1 = n1.getAttributes(); NamedNodeMap attrs2 = n2.getAttributes(); if (!isEqual(attrs1, attrs2)) { return false; } short nodeType = n1.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: return isDeepEqual(filterOutEmptyTextNodes(n1.getChildNodes()), filterOutEmptyTextNodes(n2.getChildNodes())); case Node.TEXT_NODE: return isTextNodeEqual(n1, n2); case Node.CDATA_SECTION_NODE: return isTextNodeEqual(n1, n2); default: break; } return true; }
From source file:org.eclipse.lyo.testsuite.oslcv2.OAuthTests.java
public static Collection<Object[]> getReferencedUrls(ArrayList<Node> capabilityDOMNodesUsingXML, String base) throws IOException, XPathException, ParserConfigurationException, SAXException { //ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); String requestTokenUri = ""; String authorizationUri = ""; String accessTokenUri = ""; for (Node node : capabilityDOMNodesUsingXML) { NodeList oAuthChildren = node.getChildNodes(); requestTokenUri = null;/*w ww .java2s . c o m*/ authorizationUri = null; accessTokenUri = null; for (int j = 0; j < oAuthChildren.getLength(); j++) { Node oAuthNode = oAuthChildren.item(j); if (oAuthNode.getLocalName() == null) continue; NamedNodeMap attribs = oAuthNode.getAttributes(); if (oAuthNode.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) { if (oAuthNode.getLocalName().equals("oauthRequestTokenURI")) { requestTokenUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } else if (oAuthNode.getLocalName().equals("authorizationURI")) { authorizationUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } else if (oAuthNode.getLocalName().equals("oauthAccessTokenURI")) { accessTokenUri = attribs.getNamedItemNS(OSLCConstants.RDF, "resource").getNodeValue(); } } } if (requestTokenUri != null && authorizationUri != null && accessTokenUri != null) data.add(new Object[] { base, requestTokenUri, authorizationUri, accessTokenUri }); } // If service provider didn't provide OAuth parameters, see if they // were provided in test configuration parameters. if (data.isEmpty()) { requestTokenUri = setupProps.getProperty("OAuthRequestTokenUrl"); authorizationUri = setupProps.getProperty("OAuthAuthorizationUrl"); accessTokenUri = setupProps.getProperty("OAuthAccessTokenUrl"); if (requestTokenUri != null && authorizationUri != null && accessTokenUri != null) data.add(new Object[] { base, requestTokenUri, authorizationUri, accessTokenUri }); } return data; }
From source file:Main.java
/** * Returns the path expression for a given node. * Path expressions look like: Foo.Bar.Poo where elements are * separated with a dot character./*from w w w .j a va 2 s . c o m*/ * * @param node in DOM tree. * @return the path expression representing the node in DOM tree. */ public static String getNodesPathName(Node node) { final StringBuffer buffer = new StringBuffer(); if (node.getNodeType() == Node.ATTRIBUTE_NODE) { buildNodeName(((Attr) node).getOwnerElement(), buffer); buffer.append("."); buffer.append(node.getLocalName()); } else { buildNodeName(node, buffer); } return buffer.toString(); }