本文整理汇总了Java中org.w3c.dom.Node.getPrefix方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getPrefix方法的具体用法?Java Node.getPrefix怎么用?Java Node.getPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupNamespaceURI
import org.w3c.dom.Node; //导入方法依赖的package包/类
public String lookupNamespaceURI(Node node, List<? extends Node> pathToRoot) {
String prefix = node.getPrefix();
if (prefix == null) prefix = ""; //NOI18N
String namespace = node.lookupNamespaceURI(prefix);
if (namespace == null) {
boolean skipDeeperNodes = true;
for (Node n : pathToRoot) {
if (skipDeeperNodes) {
// The target node has to be inside of pathToRoot.
// But it can be not a top element of the list.
// It's necessary to skip items until the target node
// isn't found in the list.
if (areSameNodes(n, node)) {
skipDeeperNodes = false;
}
} else {
namespace = n.lookupNamespaceURI(prefix);
if (namespace != null) {
break;
}
}
}
}
return namespace;
}
示例2: getPrefixes
import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* @return mapping from prefix to namespace.
*/
public Map<String, String> getPrefixes() {
Map<String,String> prefixes = new HashMap<String,String>();
NamedNodeMap nodes = getPeer().getAttributes();
for (int i = 0; i < nodes.getLength(); i++) {
Node n = nodes.item(i);
String name = n.getLocalName();
String prefix = n.getPrefix();
final String xmlns = XMLConstants.XMLNS_ATTRIBUTE; //NOI18N
if (xmlns.equals(name) || // default namespace
xmlns.equals(prefix)) { // namespace prefix
String ns = n.getNodeValue();
prefixes.put(name, ns);
}
}
String defaultNamespace = prefixes.remove(XMLConstants.XMLNS_ATTRIBUTE);
if (defaultNamespace != null) {
prefixes.put(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespace);
}
return prefixes;
}
示例3: getAttributeName
import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Return an attribute's qname. Handle the case of DOM level 1 nodes.
*/
public QName getAttributeName(int index) {
if (_state == START_ELEMENT) {
Node attr = _currentAttributes.get(index);
String localName = attr.getLocalName();
if (localName != null) {
String prefix = attr.getPrefix();
String uri = attr.getNamespaceURI();
return new QName(fixNull(uri), localName, fixNull(prefix));
}
else {
return QName.valueOf(attr.getNodeName());
}
}
throw new IllegalStateException("DOMStreamReader: getAttributeName() called in illegal state");
}
示例4: fillQName
import org.w3c.dom.Node; //导入方法依赖的package包/类
private void fillQName(QName toFill, Node node) {
final String prefix = node.getPrefix();
final String localName = node.getLocalName();
final String rawName = node.getNodeName();
final String namespace = node.getNamespaceURI();
toFill.uri = (namespace != null && namespace.length() > 0) ? fSymbolTable.addSymbol(namespace) : null;
toFill.rawname = (rawName != null) ? fSymbolTable.addSymbol(rawName) : XMLSymbols.EMPTY_STRING;
// Is this a DOM level1 document?
if (localName == null) {
int k = rawName.indexOf(':');
if (k > 0) {
toFill.prefix = fSymbolTable.addSymbol(rawName.substring(0, k));
toFill.localpart = fSymbolTable.addSymbol(rawName.substring(k + 1));
}
else {
toFill.prefix = XMLSymbols.EMPTY_STRING;
toFill.localpart = toFill.rawname;
}
}
else {
toFill.prefix = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING;
toFill.localpart = (localName != null) ? fSymbolTable.addSymbol(localName) : XMLSymbols.EMPTY_STRING;
}
}
示例5: getQName
import org.w3c.dom.Node; //导入方法依赖的package包/类
public static QName getQName(Node n) {
String namespace = n.getNamespaceURI();
String localName = n.getLocalName();
String prefix = n.getPrefix();
assert(localName != null);
if (namespace == null && prefix == null) {
return new QName(localName);
} else if (namespace != null && prefix == null) {
return new QName(namespace, localName);
} else {
return new QName(namespace, localName, prefix);
}
}
示例6: getPrefix
import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Get any prefix from the specified node.
* @param node the node to check
* @return String xml prefix
*/
public static String getPrefix(Node node) {
String prefix = node.getPrefix();
if (prefix != null) {
return prefix;
}
String name = node.getNodeName();
int index = name.lastIndexOf(':');
return index < 0 ? null : name.substring(0, index);
}
示例7: getPrefix
import org.w3c.dom.Node; //导入方法依赖的package包/类
public static String getPrefix(Node node) {
String prefix = node.getPrefix();
if (prefix == null) {
prefix = node.getNodeName();
// If the document is not namespace aware, we must split the attribute name
// with ':' character.
int i = prefix.indexOf(':');
if (i != -1) {
prefix = prefix.substring(0, i);
}
}
return prefix;
}
示例8: lookupNamespaceURI
import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Looks up the namespace URI associated with the given prefix starting at the given element. This method differs
* from the {@link Node#lookupNamespaceURI(java.lang.String)} in that it only those namespaces declared by an xmlns
* attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
* call like {@link Document#createElementNS(java.lang.String, java.lang.String)} even if the resulting element
* doesn't have an namespace delcaration attribute.
*
* @param startingElement the starting element
* @param stopingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
* search
* @param prefix the prefix to look up
*
* @return the namespace URI for the given prefer or null
*/
public static String lookupNamespaceURI(Element startingElement, Element stopingElement, String prefix) {
String namespaceURI;
// This code is a modified version of the lookup code within Xerces
if (startingElement.hasAttributes()) {
NamedNodeMap map = startingElement.getAttributes();
int length = map.getLength();
for (int i = 0; i < length; i++) {
Node attr = map.item(i);
String attrPrefix = attr.getPrefix();
String value = attr.getNodeValue();
namespaceURI = attr.getNamespaceURI();
if (namespaceURI != null && namespaceURI.equals(XMLConstants.XMLNS_NS)) {
// at this point we are dealing with DOM Level 2 nodes only
if (prefix == null && attr.getNodeName().equals(XMLConstants.XMLNS_PREFIX)) {
// default namespace
return value;
} else if (attrPrefix != null && attrPrefix.equals(XMLConstants.XMLNS_PREFIX)
&& attr.getLocalName().equals(prefix)) {
// non default namespace
return value;
}
}
}
}
if (startingElement != stopingElement) {
Element ancestor = getElementAncestor(startingElement);
if (ancestor != null) {
return lookupNamespaceURI(ancestor, stopingElement, prefix);
}
}
return null;
}
示例9: lookupPrefix
import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Looks up the namespace prefix associated with the given URI starting at the given element. This method differs
* from the {@link Node#lookupPrefix(java.lang.String)} in that it only those namespaces declared by an xmlns
* attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
* call like {@link Document#createElementNS(java.lang.String, java.lang.String)} even if the resulting element
* doesn't have an namespace delcaration attribute.
*
* @param startingElement the starting element
* @param stopingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
* search
* @param namespaceURI the uri to look up
*
* @return the prefix for the given namespace URI
*/
public static String lookupPrefix(Element startingElement, Element stopingElement, String namespaceURI) {
String namespace;
// This code is a modified version of the lookup code within Xerces
if (startingElement.hasAttributes()) {
NamedNodeMap map = startingElement.getAttributes();
int length = map.getLength();
for (int i = 0; i < length; i++) {
Node attr = map.item(i);
String attrPrefix = attr.getPrefix();
String value = attr.getNodeValue();
namespace = attr.getNamespaceURI();
if (namespace != null && namespace.equals(XMLConstants.XMLNS_NS)) {
// DOM Level 2 nodes
if (attr.getNodeName().equals(XMLConstants.XMLNS_PREFIX)
|| (attrPrefix != null && attrPrefix.equals(XMLConstants.XMLNS_PREFIX))
&& value.equals(namespaceURI)) {
String localname = attr.getLocalName();
String foundNamespace = startingElement.lookupNamespaceURI(localname);
if (foundNamespace != null && foundNamespace.equals(namespaceURI)) {
return localname;
}
}
}
}
}
if (startingElement != stopingElement) {
Element ancestor = getElementAncestor(startingElement);
if (ancestor != null) {
return lookupPrefix(ancestor, stopingElement, namespaceURI);
}
}
return null;
}
示例10: processAttributes
import org.w3c.dom.Node; //导入方法依赖的package包/类
private void processAttributes(Node xmlNode, Map<String, Object> nodeObject) {
NamedNodeMap attributesMap = xmlNode.getAttributes();
int attrCount = attributesMap.getLength();
for (int attrIndex = 0; attrIndex < attrCount; attrIndex++) {
Node attributeNode = attributesMap.item(attrIndex);
if (attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) {
String prefix = attributeNode.getPrefix() != null ? attributeNode.getPrefix() : "";
nodeObject.put("$" + prefix + attributeNode.getNodeName(), attributeNode.getNodeValue());
}
}
}
示例11: processNode
import org.w3c.dom.Node; //导入方法依赖的package包/类
private Object processNode(Node xmlNode) {
if (xmlNode.getNodeType() == Node.ELEMENT_NODE) {
Map<String, Object> nodeObject = new HashMap<>();
processAttributes(xmlNode, nodeObject);
StringBuilder nodeText = null;
NodeList nodeList = xmlNode.getChildNodes();
int childCount = nodeList.getLength();
for (int childIndex = 0; childIndex < childCount; childIndex++) {
Node childNode = nodeList.item(childIndex);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
String prefix = childNode.getPrefix() != null ? childNode.getPrefix() : "";
nodeObject.put(prefix + childNode.getNodeName(), processNode(childNode));
} else if (childNode.getNodeType() == Node.TEXT_NODE) {
if (nodeText == null) {
nodeText = new StringBuilder();
}
nodeText.append(childNode.getTextContent());
}
}
if (nodeText != null) {
nodeObject.put("$$text", nodeText.toString());
}
return nodeObject;
} else if (xmlNode.getNodeType() == Node.ATTRIBUTE_NODE) {
return xmlNode.getNodeValue();
} else if (xmlNode.getNodeType() == Node.TEXT_NODE) {
return xmlNode.getNodeValue();
} else {
return null;
}
}
示例12: printlnCommon
import org.w3c.dom.Node; //导入方法依赖的package包/类
private static void printlnCommon(Node n) {
logger.log(Level.FINE, " nodeName=\"" + n.getNodeName() + "\"");
String val = n.getNamespaceURI();
if (val != null) {
logger.log(Level.FINE, " uri=\"" + val + "\"");
}
val = n.getPrefix();
if (val != null) {
logger.log(Level.FINE, " pre=\"" + val + "\"");
}
val = n.getLocalName();
if (val != null) {
logger.log(Level.FINE, " local=\"" + val + "\"");
}
val = n.getNodeValue();
if (val != null) {
logger.log(Level.FINE, " nodeValue=");
if (val.trim().equals("")) {
// Whitespace
logger.log(Level.FINE, "[WS]");
} else {
logger.log(Level.FINE, "\"" + n.getNodeValue() + "\"");
}
}
}
示例13: updateQName
import org.w3c.dom.Node; //导入方法依赖的package包/类
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;
}
示例14: printlnCommon
import org.w3c.dom.Node; //导入方法依赖的package包/类
public static void printlnCommon(Node n) {
System.out.print(" nodeName=\"" + n.getNodeName() + "\"");
String val = n.getNamespaceURI();
if (val != null) {
System.out.print(" uri=\"" + val + "\"");
}
val = n.getPrefix();
if (val != null) {
System.out.print(" pre=\"" + val + "\"");
}
val = n.getLocalName();
if (val != null) {
System.out.print(" local=\"" + val + "\"");
}
val = n.getNodeValue();
if (val != null) {
System.out.print(" nodeValue=");
if (val.trim().equals("")) {
// Whitespace
System.out.print("[WS]");
} else {
System.out.print("\"" + n.getNodeValue() + "\"");
}
}
System.out.println();
}
示例15: getPrefix
import org.w3c.dom.Node; //导入方法依赖的package包/类
public static String getPrefix(Node node) {
return node.getPrefix();
}