org.w3c.dom.Element.getNamespaceURI()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(441)

本文整理了Java中org.w3c.dom.Element.getNamespaceURI()方法的一些代码示例,展示了Element.getNamespaceURI()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getNamespaceURI()方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:getNamespaceURI

Element.getNamespaceURI介绍

暂无

代码示例

代码示例来源:origin: plutext/docx4j

  1. private QName getQName(Element el) {
  2. QName qname = new QName(el.getNamespaceURI(), el.getLocalName());
  3. System.out.println(qname);
  4. return qname;
  5. }

代码示例来源:origin: plutext/docx4j

  1. /**
  2. * Returns true if the element is in XML Signature namespace and the local
  3. * name equals the supplied one.
  4. *
  5. * @param element
  6. * @param localName
  7. * @return true if the element is in XML Signature namespace and the local name equals
  8. * the supplied one
  9. */
  10. public static boolean elementIsInSignatureSpace(Element element, String localName) {
  11. if (element == null){
  12. return false;
  13. }
  14. return Constants.SignatureSpecNS.equals(element.getNamespaceURI())
  15. && element.getLocalName().equals(localName);
  16. }

代码示例来源:origin: TeamNewPipe/NewPipe

  1. private static NodeList selectNodes(Document xml, String[] path, String namespaceUri) throws XPathExpressionException {
  2. Element ref = xml.getDocumentElement();
  3. for (int i = 0; i < path.length - 1; i++) {
  4. NodeList nodes = ref.getChildNodes();
  5. if (nodes.getLength() < 1) {
  6. return null;
  7. }
  8. Element elem;
  9. for (int j = 0; j < nodes.getLength(); j++) {
  10. if (nodes.item(j).getNodeType() == Node.ELEMENT_NODE) {
  11. elem = (Element) nodes.item(j);
  12. if (elem.getNodeName().equals(path[i]) && elem.getNamespaceURI().equals(namespaceUri)) {
  13. ref = elem;
  14. break;
  15. }
  16. }
  17. }
  18. }
  19. return ref.getElementsByTagNameNS(namespaceUri, path[path.length - 1]);
  20. }

代码示例来源:origin: spring-projects/spring-integration

  1. private void configureXPathExpression(Element element, BeanDefinitionBuilder selectorBuilder, ParserContext parserContext) {
  2. String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
  3. NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
  4. Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "At most one xpath-expression child may be specified.");
  5. boolean xPathExpressionChildPresent = xPathExpressionNodes.getLength() == 1;
  6. boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
  7. Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
  8. "Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
  9. if (xPathExpressionChildPresent) {
  10. BeanDefinition beanDefinition = this.xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
  11. selectorBuilder.addConstructorArgValue(beanDefinition);
  12. }
  13. else {
  14. selectorBuilder.addConstructorArgReference(xPathExpressionRef);
  15. }
  16. }

代码示例来源:origin: apache/geode

  1. @Test
  2. public void testUpgradeSchemaFromGemfireNamespace() throws Exception {
  3. Document doc = XmlUtils.createDocumentFromXml(CLUSTER8_XML);
  4. Element oldRoot = doc.getDocumentElement();
  5. assertThat(oldRoot.getAttribute(CacheXml.VERSION)).isEqualTo("8.1");
  6. assertThat(oldRoot.getNamespaceURI()).isEqualTo(CacheXml.GEMFIRE_NAMESPACE);
  7. assertThat(oldRoot.getAttribute("xsi:schemaLocation")).isEqualTo(GEMFIRE_SCHEMA_LOCATION);
  8. String version = "1.0";
  9. doc = XmlUtils.upgradeSchema(doc, GEODE_NAMESPACE, LATEST_SCHEMA_LOCATION, version);
  10. Element root = doc.getDocumentElement();
  11. assertThat(root.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
  12. assertThat(root.getAttribute(CacheXml.VERSION)).isEqualTo(version);
  13. assertThat(root.getAttribute("xsi:schemaLocation")).isEqualTo(GEODE_SCHEMA_LOCATION);
  14. Node regionNode = root.getElementsByTagName("region").item(0);
  15. assertThat(regionNode.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
  16. }

代码示例来源:origin: 4thline/cling

  1. public static String documentToString(Document document, boolean standalone) throws Exception {
  2. String prol = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"" + (standalone ? "yes" : "no") + "\"?>";
  3. return prol + nodeToString(document.getDocumentElement(), new HashSet<String>(), document.getDocumentElement().getNamespaceURI());
  4. }

代码示例来源:origin: plutext/docx4j

  1. /**
  2. * @param signatureElement
  3. * @return the node that is the signature
  4. * @throws TransformationException
  5. */
  6. private static Node searchSignatureElement(Node signatureElement)
  7. throws TransformationException {
  8. boolean found = false;
  9. while (true) {
  10. if (signatureElement == null
  11. || signatureElement.getNodeType() == Node.DOCUMENT_NODE) {
  12. break;
  13. }
  14. Element el = (Element) signatureElement;
  15. if (el.getNamespaceURI().equals(Constants.SignatureSpecNS)
  16. && el.getLocalName().equals(Constants._TAG_SIGNATURE)) {
  17. found = true;
  18. break;
  19. }
  20. signatureElement = signatureElement.getParentNode();
  21. }
  22. if (!found) {
  23. throw new TransformationException(
  24. "transform.envelopedSignatureTransformNotInSignatureElement");
  25. }
  26. return signatureElement;
  27. }

代码示例来源:origin: marytts/marytts

  1. Document doc = (a.getNodeType() == Node.DOCUMENT_NODE) ? (Document) a : a.getOwnerDocument();
  2. Element newElement = doc.createElementNS(doc.getDocumentElement().getNamespaceURI(), newElementName);

代码示例来源:origin: ehcache/ehcache3

  1. public XmlConfigurationWrapper documentToConfig(Document document, ClassLoader classLoader, Map<String, ClassLoader> cacheClassLoaders) throws JAXBException, ClassNotFoundException, InstantiationException, IllegalAccessException {
  2. substituteSystemProperties(document);
  3. Element root = document.getDocumentElement();
  4. QName rootName = new QName(root.getNamespaceURI(), root.getLocalName());
  5. if (!CORE_SCHEMA_ROOT_NAME.equals(rootName)) {
  6. throw new XmlConfigurationException("Expecting " + CORE_SCHEMA_ROOT_NAME + " element; found " + rootName);

代码示例来源:origin: apache/geode

  1. @Test
  2. public void testChangeNamespaceWithExistingRootNamespace() throws Exception {
  3. Document doc = XmlUtils.getDocumentBuilder().newDocument();
  4. final String ns0 = "urn:namespace0";
  5. Element root = doc.createElementNS(ns0, "root");
  6. root = (Element) doc.appendChild(root);
  7. final Element child = doc.createElementNS(ns0, "child");
  8. root.appendChild(child);
  9. final String ns2 = "urn:namespace2";
  10. final Element childWithNamespace = doc.createElementNS(ns2, "childWithNamespace");
  11. root.appendChild(childWithNamespace);
  12. root.appendChild(doc.createTextNode("some text"));
  13. assertEquals(ns0, root.getNamespaceURI());
  14. assertEquals(ns0, child.getNamespaceURI());
  15. assertEquals(ns2, childWithNamespace.getNamespaceURI());
  16. final String ns1 = "urn:namespace1";
  17. root = (Element) XmlUtils.changeNamespace(root, ns0, ns1);
  18. assertEquals(ns1, root.getNamespaceURI());
  19. assertEquals(ns1, root.getElementsByTagName("child").item(0).getNamespaceURI());
  20. assertEquals(ns2, root.getElementsByTagName("childWithNamespace").item(0).getNamespaceURI());
  21. }

代码示例来源:origin: robovm/robovm

  1. switch (node.getNodeType())
  2. String uri = elem_node.getNamespaceURI();
  3. if (uri != null) {
  4. String prefix = elem_node.getPrefix();

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

  1. String uri = e.getNamespaceURI();
  2. if(uri==null) uri="";
  3. String local = e.getLocalName();
  4. String qname = e.getTagName();
  5. if(local==null) local = qname;
  6. NodeList children = e.getChildNodes();
  7. int clen = children.getLength();
  8. for( int i=0; i<clen; i++ )
  9. visit(children.item(i));

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

  1. public XmlNode updateXML(Object jaxbObject, XmlNode xmlNode) throws JAXBException {
  2. if(jaxbObject==null || xmlNode==null) throw new IllegalArgumentException();
  3. // TODO
  4. // for now just marshal
  5. // TODO: object model independenc
  6. Element e = (Element)xmlNode;
  7. Node ns = e.getNextSibling();
  8. Node p = e.getParentNode();
  9. p.removeChild(e);
  10. // if the type object is passed, the following step is necessary to make
  11. // the marshalling successful.
  12. JaxBeanInfo bi = context.getBeanInfo(jaxbObject, true);
  13. if(!bi.isElement())
  14. jaxbObject = new JAXBElement(new QName(e.getNamespaceURI(),e.getLocalName()),bi.jaxbType,jaxbObject);
  15. getMarshaller().marshal(jaxbObject,p);
  16. Node newNode = p.getLastChild();
  17. p.removeChild(newNode);
  18. p.insertBefore(newNode,ns);
  19. return (XmlNode)newNode;
  20. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Override
  2. protected BeanDefinition doParseRouter(Element element, ParserContext parserContext) {
  3. BeanDefinitionBuilder xpathRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(XPathRouter.class);
  4. NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
  5. Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "At most one xpath-expression child may be specified.");
  6. String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
  7. IntegrationNamespaceUtils.setValueIfAttributeDefined(xpathRouterBuilder, element, "evaluate-as-string");
  8. boolean xPathExpressionChildPresent = (xPathExpressionNodes.getLength() == 1);
  9. boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
  10. Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
  11. "Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
  12. if (xPathExpressionChildPresent) {
  13. BeanDefinition beanDefinition = this.xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
  14. xpathRouterBuilder.addConstructorArgValue(beanDefinition);
  15. }
  16. else {
  17. xpathRouterBuilder.addConstructorArgReference(xPathExpressionRef);
  18. }
  19. IntegrationNamespaceUtils.setReferenceIfAttributeDefined(xpathRouterBuilder, element, "converter");
  20. return xpathRouterBuilder.getBeanDefinition();
  21. }

代码示例来源:origin: apache/geode

  1. @Test
  2. public void testUpgradeSchemaFromGemfireWithCustomPrefix() throws Exception {
  3. String xml = "<a:cache xmlns:a=\"http://schema.pivotal.io/gemfire/cache\">\n"
  4. + " <a:region name=\"one\">\n"
  5. + " <a:region-attributes scope=\"distributed-ack\" data-policy=\"replicate\"/>\n"
  6. + " </a:region>\n" + "</a:cache>";
  7. Document doc = XmlUtils.createDocumentFromXml(xml);
  8. Element oldRoot = doc.getDocumentElement();
  9. assertThat(oldRoot.getNamespaceURI()).isEqualTo(CacheXml.GEMFIRE_NAMESPACE);
  10. String version = "1.0";
  11. doc = XmlUtils.upgradeSchema(doc, GEODE_NAMESPACE, LATEST_SCHEMA_LOCATION, version);
  12. Element root = doc.getDocumentElement();
  13. assertThat(root.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
  14. assertThat(root.getAttribute(CacheXml.VERSION)).isEqualTo(version);
  15. assertThat(root.getAttribute("xsi:schemaLocation")).isEqualTo(GEODE_SCHEMA_LOCATION);
  16. Node regionNode = root.getElementsByTagNameNS(GEODE_NAMESPACE, "region").item(0);
  17. assertThat(regionNode.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
  18. }

代码示例来源:origin: 4thline/cling

  1. public static String documentToFragmentString(Document document) throws Exception {
  2. return nodeToString(document.getDocumentElement(), new HashSet<String>(), document.getDocumentElement().getNamespaceURI());
  3. }

代码示例来源:origin: org.wso2.bpel/ode-bpel-epr

  1. public boolean accept(Node node) {
  2. if (node.getNodeType() == Node.ELEMENT_NODE) {
  3. Element elmt = (Element) node;
  4. if (elmt.getLocalName().equals("service-ref") &&
  5. (elmt.getNamespaceURI().equals(Namespaces.WS_BPEL_20_NS) ||
  6. elmt.getNamespaceURI().equals(Namespaces.WSBPEL2_0_FINAL_SERVREF)))
  7. elmt= DOMUtils.getFirstChildElement(elmt);
  8. if (elmt.getLocalName().equals("service") && elmt.getNamespaceURI().equals(Namespaces.WSDL_11))
  9. return true;
  10. }
  11. return false;
  12. }

代码示例来源:origin: marytts/marytts

  1. Document doc = (a.getNodeType() == Node.DOCUMENT_NODE) ? (Document) a : a.getOwnerDocument();
  2. Element newElement = doc.createElementNS(doc.getDocumentElement().getNamespaceURI(), newElementName);

代码示例来源:origin: apache/geode

  1. /**
  2. * Test method for {@link XmlUtils#changeNamespace(Node, String, String)}.
  3. */
  4. @Test
  5. public void testChangeNamespaceWithNoRootNamespace() throws Exception {
  6. Document doc = XmlUtils.getDocumentBuilder().newDocument();
  7. Element root = doc.createElement("root");
  8. root = (Element) doc.appendChild(root);
  9. final Element child = doc.createElement("child");
  10. root.appendChild(child);
  11. final String ns2 = "urn:namespace2";
  12. final Element childWithNamespace = doc.createElementNS(ns2, "childWithNamespace");
  13. root.appendChild(childWithNamespace);
  14. root.appendChild(doc.createTextNode("some text"));
  15. assertEquals(null, root.getNamespaceURI());
  16. assertEquals(null, child.getNamespaceURI());
  17. assertEquals(ns2, childWithNamespace.getNamespaceURI());
  18. final String ns1 = "urn:namespace1";
  19. root = (Element) XmlUtils.changeNamespace(root, XMLConstants.NULL_NS_URI, ns1);
  20. assertEquals(ns1, root.getNamespaceURI());
  21. assertEquals(ns1, root.getElementsByTagName("child").item(0).getNamespaceURI());
  22. assertEquals(ns2, root.getElementsByTagName("childWithNamespace").item(0).getNamespaceURI());
  23. }

代码示例来源:origin: plutext/docx4j

  1. switch (node.getNodeType())
  2. String uri = elem_node.getNamespaceURI();
  3. if (uri != null) {
  4. String prefix = elem_node.getPrefix();

相关文章