本文整理了Java中org.w3c.dom.Element.getNamespaceURI()
方法的一些代码示例,展示了Element.getNamespaceURI()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getNamespaceURI()
方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:getNamespaceURI
暂无
代码示例来源:origin: plutext/docx4j
private QName getQName(Element el) {
QName qname = new QName(el.getNamespaceURI(), el.getLocalName());
System.out.println(qname);
return qname;
}
代码示例来源:origin: plutext/docx4j
/**
* Returns true if the element is in XML Signature namespace and the local
* name equals the supplied one.
*
* @param element
* @param localName
* @return true if the element is in XML Signature namespace and the local name equals
* the supplied one
*/
public static boolean elementIsInSignatureSpace(Element element, String localName) {
if (element == null){
return false;
}
return Constants.SignatureSpecNS.equals(element.getNamespaceURI())
&& element.getLocalName().equals(localName);
}
代码示例来源:origin: TeamNewPipe/NewPipe
private static NodeList selectNodes(Document xml, String[] path, String namespaceUri) throws XPathExpressionException {
Element ref = xml.getDocumentElement();
for (int i = 0; i < path.length - 1; i++) {
NodeList nodes = ref.getChildNodes();
if (nodes.getLength() < 1) {
return null;
}
Element elem;
for (int j = 0; j < nodes.getLength(); j++) {
if (nodes.item(j).getNodeType() == Node.ELEMENT_NODE) {
elem = (Element) nodes.item(j);
if (elem.getNodeName().equals(path[i]) && elem.getNamespaceURI().equals(namespaceUri)) {
ref = elem;
break;
}
}
}
}
return ref.getElementsByTagNameNS(namespaceUri, path[path.length - 1]);
}
代码示例来源:origin: spring-projects/spring-integration
private void configureXPathExpression(Element element, BeanDefinitionBuilder selectorBuilder, ParserContext parserContext) {
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "At most one xpath-expression child may be specified.");
boolean xPathExpressionChildPresent = xPathExpressionNodes.getLength() == 1;
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
"Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
if (xPathExpressionChildPresent) {
BeanDefinition beanDefinition = this.xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
selectorBuilder.addConstructorArgValue(beanDefinition);
}
else {
selectorBuilder.addConstructorArgReference(xPathExpressionRef);
}
}
代码示例来源:origin: apache/geode
@Test
public void testUpgradeSchemaFromGemfireNamespace() throws Exception {
Document doc = XmlUtils.createDocumentFromXml(CLUSTER8_XML);
Element oldRoot = doc.getDocumentElement();
assertThat(oldRoot.getAttribute(CacheXml.VERSION)).isEqualTo("8.1");
assertThat(oldRoot.getNamespaceURI()).isEqualTo(CacheXml.GEMFIRE_NAMESPACE);
assertThat(oldRoot.getAttribute("xsi:schemaLocation")).isEqualTo(GEMFIRE_SCHEMA_LOCATION);
String version = "1.0";
doc = XmlUtils.upgradeSchema(doc, GEODE_NAMESPACE, LATEST_SCHEMA_LOCATION, version);
Element root = doc.getDocumentElement();
assertThat(root.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
assertThat(root.getAttribute(CacheXml.VERSION)).isEqualTo(version);
assertThat(root.getAttribute("xsi:schemaLocation")).isEqualTo(GEODE_SCHEMA_LOCATION);
Node regionNode = root.getElementsByTagName("region").item(0);
assertThat(regionNode.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
}
代码示例来源:origin: 4thline/cling
public static String documentToString(Document document, boolean standalone) throws Exception {
String prol = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"" + (standalone ? "yes" : "no") + "\"?>";
return prol + nodeToString(document.getDocumentElement(), new HashSet<String>(), document.getDocumentElement().getNamespaceURI());
}
代码示例来源:origin: plutext/docx4j
/**
* @param signatureElement
* @return the node that is the signature
* @throws TransformationException
*/
private static Node searchSignatureElement(Node signatureElement)
throws TransformationException {
boolean found = false;
while (true) {
if (signatureElement == null
|| signatureElement.getNodeType() == Node.DOCUMENT_NODE) {
break;
}
Element el = (Element) signatureElement;
if (el.getNamespaceURI().equals(Constants.SignatureSpecNS)
&& el.getLocalName().equals(Constants._TAG_SIGNATURE)) {
found = true;
break;
}
signatureElement = signatureElement.getParentNode();
}
if (!found) {
throw new TransformationException(
"transform.envelopedSignatureTransformNotInSignatureElement");
}
return signatureElement;
}
代码示例来源:origin: marytts/marytts
Document doc = (a.getNodeType() == Node.DOCUMENT_NODE) ? (Document) a : a.getOwnerDocument();
Element newElement = doc.createElementNS(doc.getDocumentElement().getNamespaceURI(), newElementName);
代码示例来源:origin: ehcache/ehcache3
public XmlConfigurationWrapper documentToConfig(Document document, ClassLoader classLoader, Map<String, ClassLoader> cacheClassLoaders) throws JAXBException, ClassNotFoundException, InstantiationException, IllegalAccessException {
substituteSystemProperties(document);
Element root = document.getDocumentElement();
QName rootName = new QName(root.getNamespaceURI(), root.getLocalName());
if (!CORE_SCHEMA_ROOT_NAME.equals(rootName)) {
throw new XmlConfigurationException("Expecting " + CORE_SCHEMA_ROOT_NAME + " element; found " + rootName);
代码示例来源:origin: apache/geode
@Test
public void testChangeNamespaceWithExistingRootNamespace() throws Exception {
Document doc = XmlUtils.getDocumentBuilder().newDocument();
final String ns0 = "urn:namespace0";
Element root = doc.createElementNS(ns0, "root");
root = (Element) doc.appendChild(root);
final Element child = doc.createElementNS(ns0, "child");
root.appendChild(child);
final String ns2 = "urn:namespace2";
final Element childWithNamespace = doc.createElementNS(ns2, "childWithNamespace");
root.appendChild(childWithNamespace);
root.appendChild(doc.createTextNode("some text"));
assertEquals(ns0, root.getNamespaceURI());
assertEquals(ns0, child.getNamespaceURI());
assertEquals(ns2, childWithNamespace.getNamespaceURI());
final String ns1 = "urn:namespace1";
root = (Element) XmlUtils.changeNamespace(root, ns0, ns1);
assertEquals(ns1, root.getNamespaceURI());
assertEquals(ns1, root.getElementsByTagName("child").item(0).getNamespaceURI());
assertEquals(ns2, root.getElementsByTagName("childWithNamespace").item(0).getNamespaceURI());
}
代码示例来源:origin: robovm/robovm
switch (node.getNodeType())
String uri = elem_node.getNamespaceURI();
if (uri != null) {
String prefix = elem_node.getPrefix();
代码示例来源:origin: com.sun.xml.bind/jaxb-impl
String uri = e.getNamespaceURI();
if(uri==null) uri="";
String local = e.getLocalName();
String qname = e.getTagName();
if(local==null) local = qname;
NodeList children = e.getChildNodes();
int clen = children.getLength();
for( int i=0; i<clen; i++ )
visit(children.item(i));
代码示例来源:origin: com.sun.xml.bind/jaxb-impl
public XmlNode updateXML(Object jaxbObject, XmlNode xmlNode) throws JAXBException {
if(jaxbObject==null || xmlNode==null) throw new IllegalArgumentException();
// TODO
// for now just marshal
// TODO: object model independenc
Element e = (Element)xmlNode;
Node ns = e.getNextSibling();
Node p = e.getParentNode();
p.removeChild(e);
// if the type object is passed, the following step is necessary to make
// the marshalling successful.
JaxBeanInfo bi = context.getBeanInfo(jaxbObject, true);
if(!bi.isElement())
jaxbObject = new JAXBElement(new QName(e.getNamespaceURI(),e.getLocalName()),bi.jaxbType,jaxbObject);
getMarshaller().marshal(jaxbObject,p);
Node newNode = p.getLastChild();
p.removeChild(newNode);
p.insertBefore(newNode,ns);
return (XmlNode)newNode;
}
代码示例来源:origin: spring-projects/spring-integration
@Override
protected BeanDefinition doParseRouter(Element element, ParserContext parserContext) {
BeanDefinitionBuilder xpathRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(XPathRouter.class);
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
Assert.isTrue(xPathExpressionNodes.getLength() <= 1, "At most one xpath-expression child may be specified.");
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
IntegrationNamespaceUtils.setValueIfAttributeDefined(xpathRouterBuilder, element, "evaluate-as-string");
boolean xPathExpressionChildPresent = (xPathExpressionNodes.getLength() == 1);
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
"Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
if (xPathExpressionChildPresent) {
BeanDefinition beanDefinition = this.xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
xpathRouterBuilder.addConstructorArgValue(beanDefinition);
}
else {
xpathRouterBuilder.addConstructorArgReference(xPathExpressionRef);
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(xpathRouterBuilder, element, "converter");
return xpathRouterBuilder.getBeanDefinition();
}
代码示例来源:origin: apache/geode
@Test
public void testUpgradeSchemaFromGemfireWithCustomPrefix() throws Exception {
String xml = "<a:cache xmlns:a=\"http://schema.pivotal.io/gemfire/cache\">\n"
+ " <a:region name=\"one\">\n"
+ " <a:region-attributes scope=\"distributed-ack\" data-policy=\"replicate\"/>\n"
+ " </a:region>\n" + "</a:cache>";
Document doc = XmlUtils.createDocumentFromXml(xml);
Element oldRoot = doc.getDocumentElement();
assertThat(oldRoot.getNamespaceURI()).isEqualTo(CacheXml.GEMFIRE_NAMESPACE);
String version = "1.0";
doc = XmlUtils.upgradeSchema(doc, GEODE_NAMESPACE, LATEST_SCHEMA_LOCATION, version);
Element root = doc.getDocumentElement();
assertThat(root.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
assertThat(root.getAttribute(CacheXml.VERSION)).isEqualTo(version);
assertThat(root.getAttribute("xsi:schemaLocation")).isEqualTo(GEODE_SCHEMA_LOCATION);
Node regionNode = root.getElementsByTagNameNS(GEODE_NAMESPACE, "region").item(0);
assertThat(regionNode.getNamespaceURI()).isEqualTo(GEODE_NAMESPACE);
}
代码示例来源:origin: 4thline/cling
public static String documentToFragmentString(Document document) throws Exception {
return nodeToString(document.getDocumentElement(), new HashSet<String>(), document.getDocumentElement().getNamespaceURI());
}
代码示例来源:origin: org.wso2.bpel/ode-bpel-epr
public boolean accept(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element elmt = (Element) node;
if (elmt.getLocalName().equals("service-ref") &&
(elmt.getNamespaceURI().equals(Namespaces.WS_BPEL_20_NS) ||
elmt.getNamespaceURI().equals(Namespaces.WSBPEL2_0_FINAL_SERVREF)))
elmt= DOMUtils.getFirstChildElement(elmt);
if (elmt.getLocalName().equals("service") && elmt.getNamespaceURI().equals(Namespaces.WSDL_11))
return true;
}
return false;
}
代码示例来源:origin: marytts/marytts
Document doc = (a.getNodeType() == Node.DOCUMENT_NODE) ? (Document) a : a.getOwnerDocument();
Element newElement = doc.createElementNS(doc.getDocumentElement().getNamespaceURI(), newElementName);
代码示例来源:origin: apache/geode
/**
* Test method for {@link XmlUtils#changeNamespace(Node, String, String)}.
*/
@Test
public void testChangeNamespaceWithNoRootNamespace() throws Exception {
Document doc = XmlUtils.getDocumentBuilder().newDocument();
Element root = doc.createElement("root");
root = (Element) doc.appendChild(root);
final Element child = doc.createElement("child");
root.appendChild(child);
final String ns2 = "urn:namespace2";
final Element childWithNamespace = doc.createElementNS(ns2, "childWithNamespace");
root.appendChild(childWithNamespace);
root.appendChild(doc.createTextNode("some text"));
assertEquals(null, root.getNamespaceURI());
assertEquals(null, child.getNamespaceURI());
assertEquals(ns2, childWithNamespace.getNamespaceURI());
final String ns1 = "urn:namespace1";
root = (Element) XmlUtils.changeNamespace(root, XMLConstants.NULL_NS_URI, ns1);
assertEquals(ns1, root.getNamespaceURI());
assertEquals(ns1, root.getElementsByTagName("child").item(0).getNamespaceURI());
assertEquals(ns2, root.getElementsByTagName("childWithNamespace").item(0).getNamespaceURI());
}
代码示例来源:origin: plutext/docx4j
switch (node.getNodeType())
String uri = elem_node.getNamespaceURI();
if (uri != null) {
String prefix = elem_node.getPrefix();
内容来源于网络,如有侵权,请联系作者删除!