List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:de.elbe5.base.data.XmlData.java
public Node findSubElement(Node parent, String localName) { if (parent == null) { return null; }//from w ww . ja va 2 s . c o m Node child = parent.getFirstChild(); while (child != null) { if ((child.getNodeType() == Node.ELEMENT_NODE) && (child.getLocalName().equals(localName))) { return child; } child = child.getNextSibling(); } return null; }
From source file:de.elbe5.base.data.XmlData.java
public List<String> getPropertiesFromXML(Node propNode) { List<String> properties; properties = new ArrayList<>(); NodeList childList = propNode.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { String nodeName = currentNode.getLocalName(); String namespace = currentNode.getNamespaceURI(); properties.add(namespace + ':' + nodeName); }/*from w w w.j a v a 2 s . c o m*/ } return properties; }
From source file:com.qcadoo.plugin.internal.descriptorparser.DefaultPluginDescriptorParser.java
private void addModules(final Node modulesNode, final Builder pluginBuilder, final String pluginIdentifier) { for (Node child : getChildNodes(modulesNode)) { ModuleFactory<?> moduleFactory = moduleFactoryAccessor.getModuleFactory(child.getLocalName()); LOG.info("Parsing module " + child.getLocalName() + " for plugin " + pluginIdentifier); Module module = moduleFactory.parse(pluginIdentifier, convertNodeToJdomElement(child)); checkNotNull(module, "Module for " + child.getLocalName() + " is null"); pluginBuilder.withModule(moduleFactory, module); }//from ww w . j av a 2 s .com }
From source file:com.gargoylesoftware.htmlunit.xml.XmlPageTest.java
/** * Tests namespace.//from ww w . j a v a 2s . c o m * @throws Exception if the test fails */ @Test public void namespace() throws Exception { final String content = "<?xml version='1.0'?>\n" + "<RDF xmlns='http://www.w3.org/1999/02/22-rdf-syntax-ns#' " + "xmlns:em='http://www.mozilla.org/2004/em-rdf#'>" + "<Description about='urn:mozilla:install-manifest'>" + "<em:name>My Plugin</em:name>" + "</Description>\n" + "</RDF>"; final XmlPage xmlPage = testDocument(content, "text/xml"); final Node node = xmlPage.getXmlDocument().getFirstChild().getFirstChild().getFirstChild(); assertEquals("em:name", node.getNodeName()); assertEquals("name", node.getLocalName()); assertEquals("http://www.mozilla.org/2004/em-rdf#", node.getNamespaceURI()); }
From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderXmlTests.java
@Test public void serviceProviderHasAtMostOnePublisher() throws XPathExpressionException { //Get the listed ServiceProvider elements NodeList providerChildren = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:ServiceProvider/*", doc, XPathConstants.NODESET); int numPublishers = 0; for (int i = 0; i < providerChildren.getLength(); i++) { Node child = providerChildren.item(i); if (child.getLocalName() != null && child.getNamespaceURI().equals(OSLCConstants.DC) && child.getLocalName().equals("publisher")) { numPublishers++;//w w w . j a va 2s .com } } assert (numPublishers <= 1); }
From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderXmlTests.java
@Test public void serviceProviderHasAtMostOneTitle() throws XPathException { //Verify that the ServiceProvider has at most one dc:title child element NodeList providerChildren = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:ServiceProvider/*", doc, XPathConstants.NODESET); int numTitles = 0; for (int i = 0; i < providerChildren.getLength(); i++) { Node child = providerChildren.item(i); if (child.getLocalName() != null && child.getLocalName().equals("title") && child.getNamespaceURI().equals(OSLCConstants.DC)) { numTitles++;/*from ww w. ja v a2s . c o m*/ } } assertTrue("Expected number of dcterms:titles to be <=1 but was:" + numTitles, numTitles <= 1); }
From source file:de.openali.odysseus.chart.factory.config.ChartLayerFactory.java
private IChartLayer[] build(final LayersType layersType, final ParametersType cascading, final ReferencableType... baseTypes) { final Set<IChartLayer> layers = new LinkedHashSet<>(); final Node node = layersType.getDomNode(); final NodeList childNodes = node.getChildNodes(); for (int index = 0; index < childNodes.getLength(); index++) { final Node child = childNodes.item(index); if (StringUtils.isEmpty(child.getLocalName())) { continue; }// ww w. ja v a 2 s. c om try { final IChartLayer layer = parse(child, cascading, baseTypes); if (layer != null) { layers.add(layer); } } catch (final Throwable t) { OdysseusChartFactory.getDefault().getLog() .log(new Status(IStatus.ERROR, OdysseusChartFactory.PLUGIN_ID, t.getLocalizedMessage(), t)); } } return layers.toArray(new IChartLayer[] {}); }
From source file:de.betterform.xml.dom.DOMUtil.java
/** * returns a canonical XPath locationpath for a given Node. Each step in the path will contain the positional * predicate of the Element. Example '/root[1]/a[1]/b[2]/c[5]/@d'. This would point to<br/> * to Attribute named 'd'<br/>//w w w .ja v a2 s . co m * on 5th Element 'c"<br/> * on 2nd Element 'b'<br/> * on first Element a<br/> * which is a child of the Document Element. * * @param node the Node where to start * @return canonical XPath locationPath for given Node or the empty string if node is null */ public static String getCanonicalPath(Node node) { if (node == null) { return ""; } if (node.getNodeType() == Node.DOCUMENT_NODE) { return "/"; } //add ourselves String canonPath; String ns = node.getNamespaceURI(); String nodeName1 = node.getNodeName(); String nodeName2 = node.getLocalName(); if (ns != null && ns.equals("http://www.w3.org/1999/xhtml") && node.getNodeName().equals(node.getLocalName())) { canonPath = "html:" + node.getNodeName(); } else { canonPath = node.getNodeName(); } if (node.getNodeType() == Node.ATTRIBUTE_NODE) { canonPath = "@" + canonPath; } else if (node.getNodeType() == Node.ELEMENT_NODE) { int position = DOMUtil.getCurrentNodesetPosition(node); //append position if we are an Element canonPath += "[" + position + "]"; } //check for parent - if there's none we're root Node parent = null; if (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.TEXT_NODE) { parent = node.getParentNode(); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { parent = ((Attr) node).getOwnerElement(); } if (parent == null) { parent = node.getOwnerDocument().getDocumentElement(); } if (parent.getNodeType() == Node.DOCUMENT_NODE || parent.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { canonPath = "/" + canonPath; } else { canonPath = DOMUtil.getCanonicalPath(parent) + "/" + canonPath; } return canonPath; }
From source file:com.evolveum.midpoint.util.DOMUtil.java
private static void showDomNode(Node node, StringBuilder sb, int level) { if (sb == null) { // buffer not provided, return immediately return;//w w w . j a va2s. c o m } // indent for (int i = 0; i < level; i++) { sb.append(" "); } if (node == null) { sb.append("null\n"); } else { sb.append(node.getNodeName()); sb.append(" ("); NamedNodeMap attributes = node.getAttributes(); boolean broken = false; if (attributes != null) { for (int ii = 0; ii < attributes.getLength(); ii++) { Node attribute = attributes.item(ii); sb.append(attribute.getPrefix()); sb.append(":"); sb.append(attribute.getLocalName()); sb.append("='"); sb.append(attribute.getNodeValue()); sb.append("',"); if (attribute.getPrefix() == null && attribute.getLocalName().equals("xmlns") && (attribute.getNodeValue() == null || attribute.getNodeValue().isEmpty())) { broken = true; } } } sb.append(")"); if (broken) { sb.append(" *** WARNING: empty default namespace"); } sb.append("\n"); NodeList childNodes = node.getChildNodes(); for (int ii = 0; ii < childNodes.getLength(); ii++) { Node subnode = childNodes.item(ii); showDomNode(subnode, sb, level + 1); } } }
From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderXmlTests.java
@Test public void prefixDefinitionsAreValid() throws XPathExpressionException { //Get all the prefix definitions NodeList prefixes = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:PrefixDefinition", doc, XPathConstants.NODESET); for (int i = 0; i < prefixes.getLength(); i++) { NodeList subNodes = (NodeList) OSLCUtils.getXPath().evaluate("./*", prefixes.item(i), XPathConstants.NODESET); int prefixCount = 0; int baseCount = 0; //Check all the children of this prefix definition for (int j = 0; j < subNodes.getLength(); j++) { Node pChild = subNodes.item(j); if (pChild.getLocalName() == null) { continue; }// w w w . j a v a2 s . c o m if (pChild.getLocalName().equals("prefix") && pChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) { prefixCount++; } if (pChild.getLocalName().equals("prefixBase") && pChild.getNamespaceURI().equals(OSLCConstants.OSLC_V2)) { baseCount++; } } //Make sure the prefix definition had 1 prefix and 1 prefixBase assertEquals(1, prefixCount); assertEquals(1, baseCount); } }