本文整理了Java中org.w3c.dom.Element.getElementsByTagNameNS()
方法的一些代码示例,展示了Element.getElementsByTagNameNS()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getElementsByTagNameNS()
方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:getElementsByTagNameNS
[英]Returns a NodeList
of all the descendant Elements
with a given local name and namespace URI in document order.
[中]按文档顺序返回所有子体Elements
的NodeList
,该子体具有给定的本地名称和命名空间URI。
代码示例来源:origin: redisson/redisson
public Element getSingleElement(Element element, String tagName) {
return (Element) element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName)
.item(0);
}
}
代码示例来源:origin: redisson/redisson
public boolean hasElement(Element element, String tagName) {
return element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName)
.getLength() > 0;
}
代码示例来源:origin: org.apache.poi/poi-ooxml
private String readElement(Document xmlDoc, String localName, String namespaceURI) {
Element el = (Element)xmlDoc.getDocumentElement().getElementsByTagNameNS(namespaceURI, localName).item(0);
if (el == null) {
return null;
}
return el.getTextContent();
}
代码示例来源:origin: redisson/redisson
private void parseNested(Element element, String eltType, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
NodeList list = element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE, eltType);
if (list.getLength() == 1) {
Element elt = (Element) list.item(0);
helper.setAttribute(elt, RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE,
helper.getAttribute(element,
RedissonNamespaceParserSupport.ID_ATTRIBUTE));
parserContext.getDelegate()
.parseCustomElement(elt, builder.getRawBeanDefinition());
}
}
}
代码示例来源: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: geotools/geotools
public void testEncodeAsFilter() throws Exception {
Document doc = encode(FilterMockData.propertyIsLike(), OGC.Filter);
// print(doc);
assertEquals(
1,
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart())
.getLength());
assertEquals(
1,
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart())
.getLength());
Element e = getElementByQName(doc, OGC.PropertyIsLike);
assertEquals("x", e.getAttribute("wildCard"));
assertEquals("y", e.getAttribute("singleChar"));
assertEquals("z", e.getAttribute("escape"));
}
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
Document doc;
Element docElem;
NodeList elementList;
doc = (Document) load("staffNS", false);
docElem = doc.getDocumentElement();
elementList = docElem.getElementsByTagNameNS("http://www.nomatch.com", "address");
assertSize("matchSize", 0, elementList);
}
/**
代码示例来源:origin: redisson/redisson
private void parseNested(Element element, String eltType, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
NodeList list = element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE, eltType);
if (list.getLength() == 1) {
Element elt = (Element) list.item(0);
helper.setAttribute(elt, RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE,
helper.getAttribute(element,
RedissonNamespaceParserSupport.ID_ATTRIBUTE));
parserContext.getDelegate()
.parseCustomElement(elt, builder.getRawBeanDefinition());
}
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
NodeList defaultTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagNameNS(TYPES_NAMESPACE_URI, DEFAULT_TAG_NAME);
int defaultTypeCount = defaultTypes.getLength();
for (int i = 0; i < defaultTypeCount; i++) {
Element element = (Element) defaultTypes.item(i);
String extension = element.getAttribute(EXTENSION_ATTRIBUTE_NAME);
String contentType = element.getAttribute(CONTENT_TYPE_ATTRIBUTE_NAME);
NodeList overrideTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagNameNS(TYPES_NAMESPACE_URI, OVERRIDE_TAG_NAME);
int overrideTypeCount = overrideTypes.getLength();
for (int i = 0; i < overrideTypeCount; i++) {
Element element = (Element) overrideTypes.item(i);
URI uri = new URI(element.getAttribute(PART_NAME_ATTRIBUTE_NAME));
PackagePartName partName = PackagingURIHelper.createPartName(uri);
代码示例来源:origin: org.apache.poi/poi-ooxml
private Element setElementTextContent(String localName, NamespaceImpl namespace, Optional<?> property, String propertyValue) {
if (!property.isPresent())
return null;
Element root = xmlDoc.getDocumentElement();
Element elem = (Element) root.getElementsByTagNameNS(namespace.getNamespaceURI(), localName).item(0);
if (elem == null) {
// missing, we add it
elem = xmlDoc.createElementNS(namespace.getNamespaceURI(), getQName(localName, namespace));
root.appendChild(elem);
}
elem.setTextContent(propertyValue);
return elem;
}
代码示例来源:origin: geotools/geotools
public void testEncodeAsFilter() throws Exception {
Document doc = encode(FilterMockData.propertyIsLike(), OGC.Filter);
// print(doc);
assertEquals(
1,
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart())
.getLength());
assertEquals(
1,
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart())
.getLength());
Element e = getElementByQName(doc, OGC.PropertyIsLike);
assertEquals("x", e.getAttribute("wildCard"));
assertEquals("y", e.getAttribute("singleChar"));
assertEquals("z", e.getAttribute("escapeChar"));
assertEquals("false", e.getAttribute("matchCase"));
}
}
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
Document doc;
Element docElem;
NodeList newList;
doc = (Document) load("staffNS", false);
docElem = doc.getDocumentElement();
newList = docElem.getElementsByTagNameNS("*", "*");
assertSize("listSize", 36, newList);
}
/**
代码示例来源:origin: redisson/redisson
public Element getSingleElement(Element element, String tagName) {
return (Element) element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName)
.item(0);
}
}
代码示例来源:origin: redisson/redisson
public boolean hasElement(Element element, String tagName) {
return element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE, tagName)
.getLength() > 0;
}
代码示例来源:origin: redisson/redisson
@Override
public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) {
NodeList list = element.getElementsByTagNameNS(
RedissonNamespaceParserSupport.REDISSON_NAMESPACE,
RedissonNamespaceParserSupport.LOCAL_CACHED_MAP_OPTIONS_ELEMENT);
Element options = null;
String id;
if (list.getLength() == 1) {
options = (Element) list.item(0);
id = invokeOptions(options, parserContext, helper);
for (int i = 0; i < options.getAttributes().getLength(); i++) {
代码示例来源:origin: org.apache.poi/poi-ooxml
Element root = xmlRelationshipsDoc.getDocumentElement();
NodeList nodeList = root.getElementsByTagNameNS(PackageNamespaces.RELATIONSHIPS, PackageRelationship.RELATIONSHIP_TAG_NAME);
int nodeCount = nodeList.getLength();
for (int i = 0; i < nodeCount; i++) {
Element element = (Element)nodeList.item(i);
代码示例来源: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: geotools/geotools
public void testBackwardLikeFilter() throws Exception {
String f =
"<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\"><ogc:PropertyIsLike wildCard=\"*\" singleChar=\"#\" escapeChar=\"!\">\n"
+ "<ogc:Literal>M*</ogc:Literal>\n"
+ "<ogc:PropertyName>gml:name</ogc:PropertyName>\n"
+ "</ogc:PropertyIsLike></ogc:Filter>";
Configuration configuration = new org.geotools.filter.v1_0.OGCConfiguration();
Parser parser = new Parser(configuration);
Filter filter = (Filter) parser.parse(new ByteArrayInputStream(f.getBytes()));
Document doc = encode(filter, OGC.Filter);
// print(doc);
assertEquals(
1,
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.PropertyName.getLocalPart())
.getLength());
assertEquals(
1,
doc.getDocumentElement()
.getElementsByTagNameNS(OGC.NAMESPACE, OGC.Literal.getLocalPart())
.getLength());
Element e = getElementByQName(doc, OGC.PropertyIsLike);
assertEquals("*", e.getAttribute("wildCard"));
assertEquals("#", e.getAttribute("singleChar"));
assertEquals("!", e.getAttribute("escape"));
}
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
Document doc;
Element element;
NodeList elementList;
doc = (Document) load("staffNS", false);
element = doc.getDocumentElement();
elementList = element.getElementsByTagNameNS("http://www.altavista.com", "*");
assertSize("elementgetelementsbytagnamens05", 1, elementList);
}
/**
代码示例来源:origin: apache/cxf
public static X509Certificate loadX509IssuerSerial(Crypto crypto, Element certNode)
throws Exception {
Node issuerNameNode =
certNode.getElementsByTagNameNS(Constants.SignatureSpecNS, "X509IssuerName").item(0);
Node serialNumberNode =
certNode.getElementsByTagNameNS(Constants.SignatureSpecNS, "X509SerialNumber").item(0);
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ISSUER_SERIAL);
cryptoType.setIssuerSerial(issuerNameNode.getTextContent(),
new BigInteger(serialNumberNode.getTextContent()));
return crypto.getX509Certificates(cryptoType)[0];
}
内容来源于网络,如有侵权,请联系作者删除!