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


Java Node.ATTRIBUTE_NODE属性代码示例

本文整理汇总了Java中org.w3c.dom.Node.ATTRIBUTE_NODE属性的典型用法代码示例。如果您正苦于以下问题:Java Node.ATTRIBUTE_NODE属性的具体用法?Java Node.ATTRIBUTE_NODE怎么用?Java Node.ATTRIBUTE_NODE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.w3c.dom.Node的用法示例。


在下文中一共展示了Node.ATTRIBUTE_NODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hasLegalRootContainer

/**
 * Finds the root container for the given node and determines
 * if that root container is legal with respect to the
 * DOM 2 specification.  At present, that means the root
 * container must be either an attribute, a document,
 * or a document fragment.
 */
private boolean hasLegalRootContainer( Node node )
{
        if ( node==null )
                return false;

        Node rootContainer = getRootContainer( node );
        switch( rootContainer.getNodeType() )
        {
        case Node.ATTRIBUTE_NODE:
        case Node.DOCUMENT_NODE:
        case Node.DOCUMENT_FRAGMENT_NODE:
                return true;
        }
        return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:RangeImpl.java

示例2: getStrFromNode

/**
 * Method getStrFromNode
 *
 * @param xpathnode
 * @return the string for the node.
 */
public static String getStrFromNode(Node xpathnode) {
    if (xpathnode.getNodeType() == Node.TEXT_NODE) {
        // we iterate over all siblings of the context node because eventually,
        // the text is "polluted" with pi's or comments
        StringBuilder sb = new StringBuilder();

        for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
            currentSibling != null;
            currentSibling = currentSibling.getNextSibling()) {
            if (currentSibling.getNodeType() == Node.TEXT_NODE) {
                sb.append(((Text) currentSibling).getData());
            }
        }

        return sb.toString();
    } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
        return ((Attr) xpathnode).getNodeValue();
    } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        return ((ProcessingInstruction) xpathnode).getNodeValue();
    }

    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:XMLUtils.java

示例3: nodeToString

private static String nodeToString(Node node) {
	int nodeType = node.getNodeType();
	switch (nodeType) {
		case Node.DOCUMENT_NODE:
			return XMLUtils.prettyPrintElement(((Document) node).getDocumentElement(), true, false);
		case Node.ELEMENT_NODE:
			return XMLUtils.prettyPrintElement((Element) node, true, false);
		case Node.CDATA_SECTION_NODE:
		case Node.TEXT_NODE:
			int len = node.getChildNodes().getLength();
			return ((len<2) ? node.getNodeValue():XMLUtils.getNormalizedText(node));
		case Node.ATTRIBUTE_NODE:
			return node.getNodeValue();
		default:
			return null;
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:17,代码来源:ParameterUtils.java

示例4: nodeCount

/**
 * Counts the number of matching nodes.
 */
public int nodeCount(final String path)
{
	ensureRoot();

	int count = 0;

	final Node node = getNodeHelper(path, false, false);
	if( node != null )
	{
		if( node.getNodeType() == Node.ATTRIBUTE_NODE )
		{
			count = 1;
		}
		else
		{
			for( final Iterator<String> iter = iterateValues(path); iter.hasNext(); count++ )
			{
				iter.next();
			}
		}
	}
	return count;
}
 
开发者ID:equella,项目名称:Equella,代码行数:26,代码来源:PropBagEx.java

示例5: toMap

public Map<String, Object> toMap(Node node) {

		Map<String, Object> map = new LinkedHashMap<String, Object>();
		for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
			if (child.getNodeType() == Node.ATTRIBUTE_NODE || child.getNodeType() == Node.ELEMENT_NODE)
				toMap(map, child);

		return map;
	}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:9,代码来源:XmlDocumentAdapter.java

示例6: addNamespacesFrom

/**
 * Adds namespaces from the tag to this context, possibly overriding namespaces
 * from previously added tags. Tags should be added starting from the root down
 * to the context position.
 */
private void addNamespacesFrom(SyntaxElement s) {
    Node e = s.getNode();
    NamedNodeMap attrs = e.getAttributes();
    String nodePrefix = getPrefix(e.getNodeName(), false);
    String version = null;
    String xsltAttrName = null;
    
    for (int i = attrs.getLength() - 1; i >= 0; i--) {
        Node n = attrs.item(i);
        if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
            Attr a = (Attr)n;
            String attrName = a.getName();
            String value = a.getValue();
            addNamespace(attrName, value, nodePrefix);

        
            if(value.trim().equals("http://www.w3.org/1999/XSL/Transform")) { //NOI18N
                xsltAttrName = attrName;
            }
            if(CompletionUtil.getLocalNameFromTag(attrName).
                    equals("version")) { //NOI18N
                version = value.trim();
            }
        } 
    }
    
    if (xsltAttrName != null && "2.0".equals(version)) {
        String prefix = getPrefix(xsltAttrName, false);
        if (prefix == null) {
            // override nonNS location because nonNS schema is XSLT 2.0
            noNamespaceSchemaLocation = "http://www.w3.org/2007/schema-for-xslt20.xsd";
        } else {
            addSchemaLocation(prefix + " http://www.w3.org/2007/schema-for-xslt20.xsd"); //NOI18N
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:CompletionContextImpl.java

示例7: hasWhitespaceChangeOnly

public boolean hasWhitespaceChangeOnly() {
    for (ChangeInfo ci : getChanges()) {
        if (ci.isDomainElement()) {
            continue;
        }
        Node n = ci.getActualChangedNode();
        if (n.getNodeType() == Node.TEXT_NODE) {
            String text = ((Text)n).getNodeValue();
            if (text != null && text.trim().length() > 0) {
                return false;
            }
        } else if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
            String name =  ((Attr) n).getName();
            Attr removed = getRemovedAttributes().get(name);
            if (removed == null) {
                return false;
            }
            Attr added = getAddedAttributes().get(name);
            if (added == null) {
                return false;
            }
            if (removed.getValue() == null || 
                ! removed.getValue().equals(added.getValue())) {
                return false;
            }
        } else {
            // node type must be either element or comment or cdata...
            return false;
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:SyncUnit.java

示例8: getParentNode

/**
 *
 *
 * @see org.w3c.dom.Node
 */
@Override
public final Node getParentNode()
{

  if (getNodeType() == Node.ATTRIBUTE_NODE)
    return null;

  int newnode = dtm.getParent(node);

  return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:DTMNodeProxy.java

示例9: getTextContent

private static String getTextContent(Node node)
{
    short nodeType = node.getNodeType();
    if( nodeType == Node.ATTRIBUTE_NODE ||
        nodeType == Node.PROCESSING_INSTRUCTION_NODE ||
        nodeType == Node.COMMENT_NODE ||
        nodeType == Node.TEXT_NODE ||
        nodeType == Node.CDATA_SECTION_NODE )
    {
        return com.altova.CoreTypes.castToString(node.getNodeValue());
    }
    else
    if( nodeType == Node.DOCUMENT_NODE ||
        nodeType == Node.DOCUMENT_FRAGMENT_NODE ||
        nodeType == Node.ELEMENT_NODE ||
        nodeType == Node.ENTITY_REFERENCE_NODE )
    {
        String result = "";
        Node child = node.getFirstChild();
        for( ; child != null ; child = child.getNextSibling() )
        {
            short childNodeType = child.getNodeType();
            if( childNodeType == Node.TEXT_NODE ||
                childNodeType == Node.CDATA_SECTION_NODE ||
                childNodeType == Node.ELEMENT_NODE ||
                childNodeType == Node.ENTITY_REFERENCE_NODE )
            {
                result += getTextContent( child );
            }
        }
        return result;
    }
    else
        return "";
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:35,代码来源:XmlTreeOperations.java

示例10: getNextSibling

/**
 *
 *
 * @see org.w3c.dom.Node
 */
@Override
public final Node getNextSibling()
{

  // Attr's Next is defined at DTM level, but not at DOM level.
  if (dtm.getNodeType(node) == Node.ATTRIBUTE_NODE)
    return null;

  int newnode = dtm.getNextSibling(node);

  return (newnode == DTM.NULL) ? null : dtm.getNode(newnode);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:DTMNodeProxy.java

示例11: getXpathData

private Document getXpathData(Document document, String xPath) {
	if (document == null) {
		return null;
	}
	if (xPath == null) {
		return null;
	}

	try {
		Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
		Element root =  (Element) doc.createElement("root"); 
		doc.appendChild(root);
		
		NodeList nl = getXpathApi().selectNodeList(document, xPath);
		if (nl != null)
			for (int i = 0; i< nl.getLength(); i++) {
				Node node = doc.importNode(nl.item(i), true);
				Element elt = doc.getDocumentElement();
				if (node.getNodeType() == Node.ELEMENT_NODE) {
					elt.appendChild(node);
				}
				if (node.getNodeType() == Node.TEXT_NODE) {
					elt.appendChild(node);
				}
				if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
					elt.setAttribute(node.getNodeName() + "_" + i, node.getNodeValue());
				}
			}

		return doc;
	} catch (TransformerException e) {
		ConvertigoPlugin.logWarning("Error for xpath : '" + xPath + "'\r " + e.getMessage());
		return null;
	}
}
 
开发者ID:convertigo,项目名称:convertigo-eclipse,代码行数:35,代码来源:XpathEvaluatorComposite.java

示例12: getNodeData

/**
 * Retrieve the text content of a DOM subtree, appending it into a
 * user-supplied FastStringBuffer object. Note that attributes are
 * not considered part of the content of an element.
 * <p>
 * There are open questions regarding whitespace stripping.
 * Currently we make no special effort in that regard, since the standard
 * DOM doesn't yet provide DTD-based information to distinguish
 * whitespace-in-element-context from genuine #PCDATA. Note that we
 * should probably also consider xml:space if/when we address this.
 * DOM Level 3 may solve the problem for us.
 *
 * @param node Node whose subtree is to be walked, gathering the
 * contents of all Text or CDATASection nodes.
 * @param buf FastStringBuffer into which the contents of the text
 * nodes are to be concatenated.
 */
public static void getNodeData(Node node, FastStringBuffer buf)
{

  switch (node.getNodeType())
  {
  case Node.DOCUMENT_FRAGMENT_NODE :
  case Node.DOCUMENT_NODE :
  case Node.ELEMENT_NODE :
  {
    for (Node child = node.getFirstChild(); null != child;
            child = child.getNextSibling())
    {
      getNodeData(child, buf);
    }
  }
  break;
  case Node.TEXT_NODE :
  case Node.CDATA_SECTION_NODE :
    buf.append(node.getNodeValue());
    break;
  case Node.ATTRIBUTE_NODE :
    buf.append(node.getNodeValue());
    break;
  case Node.PROCESSING_INSTRUCTION_NODE :
    // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
    break;
  default :
    // ignore
    break;
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:48,代码来源:DOMHelper.java

示例13: processAttributes

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,代码行数:11,代码来源:ReadXml.java

示例14: saveEnclosingAttr

/**
 * NON-DOM INTERNAL: Pre-mutation context check, in
 * preparation for later generating DOMAttrModified events.
 * Determines whether this node is within an Attr
 * @param node node to get enclosing attribute for
 * @return either a description of that Attr, or null if none such.
 */
protected void saveEnclosingAttr(NodeImpl node) {
    savedEnclosingAttr = null;
    // MUTATION PREPROCESSING AND PRE-EVENTS:
    // If we're within the scope of an Attr and DOMAttrModified
    // was requested, we need to preserve its previous value for
    // that event.
    LCount lc = LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);
    if (lc.total > 0) {
        NodeImpl eventAncestor = node;
        while (true) {
            if (eventAncestor == null)
                return;
            int type = eventAncestor.getNodeType();
            if (type == Node.ATTRIBUTE_NODE) {
                EnclosingAttr retval = new EnclosingAttr();
                retval.node = (AttrImpl) eventAncestor;
                retval.oldvalue = retval.node.getNodeValue();
                savedEnclosingAttr = retval;
                return;
            }
            else if (type == Node.ENTITY_REFERENCE_NODE)
                eventAncestor = eventAncestor.parentNode();
            else if (type == Node.TEXT_NODE)
                eventAncestor = eventAncestor.parentNode();
            else
                return;
            // Any other parent means we're not in an Attr
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:DocumentImpl.java

示例15: getXpathData

public static Document getXpathData(Document document, String xPath) {
    if (document == null) {
        return null;
    }
    if (xPath == null) {
        return null;
    }

    try {
        Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
        Element root =  (Element) doc.createElement("root"); 
        doc.appendChild(root);

        NodeList nl = new TwsCachedXPathAPI().selectNodeList(document, xPath);
        if (nl != null)
            for (int i = 0; i < nl.getLength(); i++) {
                Node node = doc.importNode(nl.item(i), true);
                Element elt = doc.getDocumentElement();
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    elt.appendChild(node);
                }
                if (node.getNodeType() == Node.TEXT_NODE) {
                    elt.appendChild(node);
                }
                if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
                    elt.setAttribute(node.getNodeName() + "_" + i, node.getNodeValue());
                }
            }

        return doc;
    }
    catch (TransformerException e) {
        //ConvertigoPlugin.logWarning("Error for xpath : '" + xPath + "'\r " + e.getMessage());
        return null;
    }
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:36,代码来源:XpathEvaluatorCompositeWrap.java


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