当前位置: 首页>>代码示例>>Java>>正文


Java Node.getPrefix方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:DocumentModelAccess.java

示例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;
  }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:AbstractDocumentComponent.java

示例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");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:DOMStreamReader.java

示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:DOMValidatorHelper.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:AbstractDocumentComponent.java

示例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);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:16,代码来源:DOMNodePointer.java

示例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;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:16,代码来源:XMLUtils.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:50,代码来源:XMLHelper.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:53,代码来源:XMLHelper.java

示例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());
        }
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:12,代码来源:ReadXml.java

示例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;
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:37,代码来源:ReadXml.java

示例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() + "\"");
        }
    }
}
 
开发者ID:RaysonYeungHK,项目名称:Svg2AndroidXml,代码行数:31,代码来源:Svg2Vector.java

示例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;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:DOMNormalizer.java

示例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();
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:32,代码来源:XMLDOMHelper.java

示例15: getPrefix

import org.w3c.dom.Node; //导入方法依赖的package包/类
public static String getPrefix(Node node) {
    return node.getPrefix();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:DOMUtil.java


注:本文中的org.w3c.dom.Node.getPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。