本文整理了Java中org.w3c.dom.Node.getNamespaceURI()
方法的一些代码示例,展示了Node.getNamespaceURI()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getNamespaceURI()
方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:getNamespaceURI
[英]The namespace URI of this node, or null
if it is unspecified (see ).
This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.
For nodes of any type other than ELEMENT_NODE
and ATTRIBUTE_NODE
and nodes created with a DOM Level 1 method, such as Document.createElement()
, this is always null
.
Note: Per the Namespaces in XML Specification [XML Namespaces] an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.
[中]此节点的命名空间URI,如果未指定,则为null
(请参阅)。
这不是一个计算值,它不是基于对范围中的命名空间声明的检查而进行的命名空间查找的结果。它只是创建时给定的名称空间URI。
对于ELEMENT_NODE
和ATTRIBUTE_NODE
之外的任何类型的节点,以及使用DOM级别1方法创建的节点,例如Document.createElement()
,这始终是null
。
注意:根据XML规范[XML Namespaces]中的名称空间,属性不会从其附加到的元素继承其名称空间。如果一个属性没有显式地给出名称空间,那么它就没有名称空间。
代码示例来源:origin: org.freemarker/freemarker
public String getNodeNamespace() {
int nodeType = node.getNodeType();
if (nodeType != Node.ATTRIBUTE_NODE && nodeType != Node.ELEMENT_NODE) {
return null;
}
String result = node.getNamespaceURI();
if (result == null && nodeType == Node.ELEMENT_NODE) {
result = "";
} else if ("".equals(result) && nodeType == Node.ATTRIBUTE_NODE) {
result = null;
}
return result;
}
代码示例来源:origin: plutext/docx4j
/**
* @param sibling
* @param uri
* @param nodeName
* @param number
* @return nodes with the constrain
*/
public static Element selectNode(Node sibling, String uri, String nodeName, int number) {
while (sibling != null) {
if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
&& sibling.getLocalName().equals(nodeName)) {
if (number == 0){
return (Element)sibling;
}
number--;
}
sibling = sibling.getNextSibling();
}
return null;
}
代码示例来源:origin: jaxen/jaxen
/**
* Constructor.
*
* @param parent the parent DOM element for the attributes.
*/
AttributeIterator (Node parent)
{
this.map = parent.getAttributes();
this.pos = 0;
for (int i = this.map.getLength()-1; i >= 0; i--) {
Node node = map.item(i);
if (! "http://www.w3.org/2000/xmlns/".equals(node.getNamespaceURI())) {
this.lastAttribute = i;
break;
}
}
}
代码示例来源:origin: robovm/robovm
/**
* Look up the index of an attribute by Namespace name.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI.
* @param localPart The attribute's local name.
* @return The index of the attribute, or -1 if it does not
* appear in the list.
*/
public int getIndex(String uri, String localPart)
{
for(int i=m_attrs.getLength()-1;i>=0;--i)
{
Node a=m_attrs.item(i);
String u=a.getNamespaceURI();
if( (u==null ? uri==null : u.equals(uri))
&&
a.getLocalName().equals(localPart) )
return i;
}
return -1;
}
代码示例来源:origin: org.netbeans.api/org-openide-util
int nodeCount = l.getLength();
for (int i = 0; i < nodeCount; i++) {
if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
Node node = l.item(i);
String localName = node.getLocalName();
localName = localName == null ? node.getNodeName() : localName;
&& (namespace == null || namespace.equals(node.getNamespaceURI()))) {
if (result == null) {
result = (Element)node;
代码示例来源:origin: robovm/robovm
Node p = (root.getNodeType() == Node.ATTRIBUTE_NODE) ? ((org.w3c.dom.Attr)root).getOwnerElement() : root.getParentNode();
for (; p != null; p = p.getParentNode())
handle=dtm.getAttributeNode(handle,node.getNamespaceURI(),node.getLocalName());
代码示例来源:origin: org.xmlunit/xmlunit-core
/**
* Extracts a Node's name, namespace URI (if any) and prefix as a
* QName.
*/
public static QName getQName(Node n) {
String s = n.getLocalName();
String p = n.getPrefix();
return s != null
? new QName(n.getNamespaceURI(), s,
p != null ? p: XMLConstants.DEFAULT_NS_PREFIX)
: new QName(n.getNodeName());
}
代码示例来源:origin: org.freemarker/freemarker
@Override
void getChildren(Object node, String localName, String namespaceUri, List result) {
if ("".equals(namespaceUri)) {
namespaceUri = null;
}
NodeList children = ((Node) node).getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
Node subnode = children.item(i);
// IMO, we should get the text nodes as well -- will discuss.
if (subnode.getNodeType() == Node.ELEMENT_NODE || subnode.getNodeType() == Node.TEXT_NODE) {
if (localName == null || (equal(subnode.getNodeName(), localName) && equal(subnode.getNamespaceURI(), namespaceUri))) {
result.add(subnode);
}
}
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
protected void write(OutputStream out) throws IOException {
XmlObject rootObject = XmlObject.Factory.newInstance();
XmlCursor rootCursor = rootObject.newCursor();
rootCursor.toNextToken();
rootCursor.beginElement("xml");
for(int i=0; i < _items.size(); i++){
XmlCursor xc = _items.get(i).newCursor();
rootCursor.beginElement(_qnames.get(i));
while(xc.toNextToken() == XmlCursor.TokenType.ATTR) {
Node anode = xc.getDomNode();
rootCursor.insertAttributeWithValue(anode.getLocalName(), anode.getNamespaceURI(), anode.getNodeValue());
}
xc.toStartDoc();
xc.copyXmlContents(rootCursor);
rootCursor.toNextToken();
xc.dispose();
}
rootCursor.dispose();
rootObject.save(out, DEFAULT_XML_OPTIONS);
}
代码示例来源:origin: org.freemarker/freemarker
private void outputQualifiedName(Node n, StringBuilder buf) {
String nsURI = n.getNamespaceURI();
if (nsURI == null || nsURI.length() == 0) {
buf.append(n.getNodeName());
} else {
String prefix = namespacesToPrefixLookup.get(nsURI);
if (prefix == null) {
//REVISIT!
buf.append(n.getNodeName());
} else {
if (prefix.length() > 0) {
buf.append(prefix);
buf.append(':');
}
buf.append(n.getLocalName());
}
}
}
代码示例来源:origin: org.netbeans.api/org-openide-util
private static void collectCDATASections(Node node, Set<String> cdataQNames) {
if (node instanceof CDATASection) {
Node parent = node.getParentNode();
if (parent != null) {
String uri = parent.getNamespaceURI();
if (uri != null) {
cdataQNames.add("{" + uri + "}" + parent.getNodeName()); //NOI18N
} else {
cdataQNames.add(parent.getNodeName());
}
}
}
NodeList children = node.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
collectCDATASections(children.item(i), cdataQNames);
}
}
代码示例来源:origin: robovm/robovm
/**
* Look up the index of an attribute by Namespace name.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI.
* @param localPart The attribute's local name.
* @return The index of the attribute, or -1 if it does not
* appear in the list.
*/
public int getIndex(String uri, String localPart)
{
for(int i=m_attrs.getLength()-1;i>=0;--i)
{
Node a=m_attrs.item(i);
String u=a.getNamespaceURI();
if( (u==null ? uri==null : u.equals(uri))
&&
a.getLocalName().equals(localPart) )
return i;
}
return -1;
}
代码示例来源:origin: robovm/robovm
values.add(node.getNodeType());
values.add(node.getNodeName());
values.add(node.getLocalName());
values.add(node.getNamespaceURI());
values.add(node.getPrefix());
values.add(node.getNodeValue());
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
values.add(child);
switch (node.getNodeType()) {
case DOCUMENT_TYPE_NODE:
DocumentTypeImpl doctype = (DocumentTypeImpl) node;
代码示例来源:origin: xalan/xalan
Node p = (root.getNodeType() == Node.ATTRIBUTE_NODE) ? ((org.w3c.dom.Attr)root).getOwnerElement() : root.getParentNode();
for (; p != null; p = p.getParentNode())
handle=dtm.getAttributeNode(handle,node.getNamespaceURI(),node.getLocalName());
代码示例来源:origin: com.sun.xml.parsers/jaxp-ri
protected final void updateQName (Node node, QName qname){
String prefix = node.getPrefix();
String namespace = node.getNamespaceURI();
String localName = node.getLocalName();
// REVISIT: the symbols are added too often: start/endElement
// and in the namespaceFixup. Should reduce number of calls to symbol table.
qname.prefix = (prefix!=null && prefix.length()!=0)?fSymbolTable.addSymbol(prefix):null;
qname.localpart = (localName != null)?fSymbolTable.addSymbol(localName):null;
qname.rawname = fSymbolTable.addSymbol(node.getNodeName());
qname.uri = (namespace != null)?fSymbolTable.addSymbol(namespace):null;
}
代码示例来源:origin: haraldk/TwelveMonkeys
private void parseAttributesForKnownElements(Map<String, List<Entry>> subdirs, Node desc) {
// NOTE: NamedNodeMap does not have any particular order...
NamedNodeMap attributes = desc.getAttributes();
for (Node attr : asIterable(attributes)) {
if (!XMP.ELEMENTS.contains(attr.getNamespaceURI())) {
continue;
}
List<Entry> dir = subdirs.get(attr.getNamespaceURI());
if (dir == null) {
dir = new ArrayList<Entry>();
subdirs.put(attr.getNamespaceURI(), dir);
}
dir.add(new XMPEntry(attr.getNamespaceURI() + attr.getLocalName(), attr.getLocalName(), attr.getNodeValue()));
}
}
代码示例来源:origin: jaxen/jaxen
/**
* Test if a node is an attribute. <code>xmlns</code> and
* <code>xmlns:pre</code> attributes do not count as attributes
* for the purposes of XPath.
*
* @param object the target node
* @return true if the node is an attribute, false otherwise
*/
public boolean isAttribute (Object object)
{
return (object instanceof Node) &&
(((Node)object).getNodeType() == Node.ATTRIBUTE_NODE)
&& ! "http://www.w3.org/2000/xmlns/".equals(((Node) object).getNamespaceURI());
}
代码示例来源:origin: org.freemarker/freemarker
@Override
String getQualifiedName() {
String nsURI = node.getNamespaceURI();
if (nsURI == null || nsURI.equals(""))
return node.getNodeName();
Environment env = Environment.getCurrentEnvironment();
String defaultNS = env.getDefaultNS();
String prefix = null;
if (nsURI.equals(defaultNS)) {
prefix = "D";
} else {
prefix = env.getPrefixForNamespace(nsURI);
}
if (prefix == null) {
return null;
}
return prefix + ":" + node.getLocalName();
}
}
代码示例来源:origin: plutext/docx4j
/**
* @param sibling
* @param uri
* @param nodeName
* @return nodes with the constraint
*/
public static Element[] selectNodes(Node sibling, String uri, String nodeName) {
List<Element> list = new ArrayList<Element>();
while (sibling != null) {
if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
&& sibling.getLocalName().equals(nodeName)) {
list.add((Element)sibling);
}
sibling = sibling.getNextSibling();
}
return list.toArray(new Element[list.size()]);
}
代码示例来源:origin: apache/geode
/**
* Change the namespace URI of a <code>node</code> and its children to
* <code>newNamespaceUri</code> if that node is in the given <code>oldNamespaceUri</code>
* namespace URI.
*
*
* @param node {@link Node} to change namespace URI on.
* @param oldNamespaceUri old namespace URI to change from.
* @param newNamespaceUri new Namespace URI to change to.
* @return the modified version of the passed in node.
* @since GemFire 8.1
*/
static Node changeNamespace(final Node node, final String oldNamespaceUri,
final String newNamespaceUri) throws XPathExpressionException {
Node result = null;
final NodeList nodes = query(node, "//*");
for (int i = 0; i < nodes.getLength(); i++) {
final Node element = nodes.item(i);
if (element.getNamespaceURI() == null || element.getNamespaceURI().equals(oldNamespaceUri)) {
Node renamed =
node.getOwnerDocument().renameNode(element, newNamespaceUri, element.getNodeName());
if (element == node) {
result = renamed;
}
}
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!