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


Java Node.COMMENT_NODE属性代码示例

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


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

示例1: findSubElements

/**
 * Find all direct child elements of an element.
 * More useful than {@link Element#getElementsByTagNameNS} because it does
 * not recurse into recursive child elements.
 * Children which are all-whitespace text nodes or comments are ignored; others cause
 * an exception to be thrown.
 * @param parent a parent element in a DOM tree
 * @return a list of direct child elements (may be empty)
 * @throws IllegalArgumentException if there are non-element children besides whitespace
 */
static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
    NodeList l = parent.getChildNodes();
    List<Element> elements = new ArrayList<>(l.getLength());
    for (int i = 0; i < l.getLength(); i++) {
        Node n = l.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            elements.add((Element)n);
        } else if (n.getNodeType() == Node.TEXT_NODE) {
            String text = ((Text)n).getNodeValue();
            if (text.trim().length() > 0) {
                throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
            }
        } else if (n.getNodeType() == Node.COMMENT_NODE) {
            // OK, ignore
        } else {
            throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
        }
    }
    return elements;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:XMLUtil.java

示例2: examineNode

/**
 * A single node is read, the namespace attributes are extracted and stored.
 * 
 * @param node
 *            to examine
 * @param attributesOnly,
 *            if true no recursion happens
 */
private void examineNode(Node node, boolean attributesOnly) {
	while(node != null && node.getNodeType() == Node.COMMENT_NODE) {
		node = node.getNextSibling();
	}
	if(node != null) {
		NamedNodeMap attributes = node.getAttributes();
		if(attributes != null) {
			for (int i = 0; i < attributes.getLength(); i++) {
				Node attribute = attributes.item(i);
				storeAttribute((Attr) attribute);
			}
		}

		if (!attributesOnly) {
			NodeList chields = node.getChildNodes();
			for (int i = 0; i < chields.getLength(); i++) {
				Node chield = chields.item(i);
				if (chield.getNodeType() == Node.ELEMENT_NODE)
					examineNode(chield, false);
			}
		}
	}
}
 
开发者ID:WinRoad-NET,项目名称:wrdocletbase,代码行数:31,代码来源:UniversalNamespaceCache.java

示例3: serialize

/**
 * Serialize a {@link Document}.
 *
 * @param d the document to serialize.
 */
public final void serialize(Document d) throws IOException {
    reset();
    encodeHeader(false);
    encodeInitialVocabulary();

    final NodeList nl = d.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        final Node n = nl.item(i);
        switch (n.getNodeType()) {
            case Node.ELEMENT_NODE:
                serializeElement(n);
                break;
            case Node.COMMENT_NODE:
                serializeComment(n);
                break;
            case Node.PROCESSING_INSTRUCTION_NODE:
                serializeProcessingInstruction(n);
                break;
        }
    }
    encodeDocumentTermination();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:DOMDocumentSerializer.java

示例4: insertSourceMarkers

private static File insertSourceMarkers(@NonNull Node node, @Nullable File currentFile) {
    for (int i = 0; i < node.getChildNodes().getLength(); i++) {
        Node child = node.getChildNodes().item(i);
        short nodeType = child.getNodeType();
        if (nodeType == Node.ELEMENT_NODE
                || nodeType == Node.COMMENT_NODE
                || nodeType == Node.DOCUMENT_NODE
                || nodeType == Node.CDATA_SECTION_NODE) {
            File file = MergerXmlUtils.getFileFor(child);
            if (file != null && !file.equals(currentFile)) {
                i += insertSourceMarker(node, child, file, false);
                currentFile = file;
            }

            currentFile = insertSourceMarkers(child, currentFile);
        }
    }

    Node lastElement = node.getLastChild();
    while (lastElement != null && lastElement.getNodeType() == Node.TEXT_NODE) {
        lastElement = lastElement.getPreviousSibling();
    }
    if (lastElement != null && lastElement.getNodeType() == Node.ELEMENT_NODE) {
        File parentFile = MergerXmlUtils.getFileFor(node);
        File lastFile = MergerXmlUtils.getFileFor(lastElement);
        if (lastFile != null && parentFile != null && !parentFile.equals(lastFile)) {
            insertSourceMarker(node, lastElement, parentFile, true);
            currentFile = parentFile;
        }
    }

    return currentFile;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:33,代码来源:ManifestMerger.java

示例5: parseControllerParameters

protected void parseControllerParameters(BeanDefinitionBuilder dwrControllerDefinition, Element parent)
{
    NodeList children = parent.getChildNodes();
    Map params = new HashMap();
    for (int i = 0; i < children.getLength(); i++)
    {
        Node node = children.item(i);

        if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE)
        {
            continue;
        }

        Element child = (Element) node;
        if (child.getNodeName().equals("dwr:config-param"))
        {
            String paramName = child.getAttribute("name");
            String value = child.getAttribute("value");
            params.put(paramName, value);
        }
        else
        {
            throw new RuntimeException("an unknown dwr:controller sub node was found: " + node.getNodeName());
        }
    }
    dwrControllerDefinition.addPropertyValue("configParams", params);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:DwrNamespaceHandler.java

示例6: getNodeTypeFromCode

private String getNodeTypeFromCode(short code) {
    String retval = null;
    switch (code) {
    case Node.ATTRIBUTE_NODE :
        retval = "ATTRIBUTE_NODE"; break;
    case Node.CDATA_SECTION_NODE :
        retval = "CDATA_SECTION_NODE"; break;
    case Node.COMMENT_NODE :
        retval = "COMMENT_NODE"; break;
    case Node.DOCUMENT_FRAGMENT_NODE :
        retval = "DOCUMENT_FRAGMENT_NODE"; break;
    case Node.DOCUMENT_NODE :
        retval = "DOCUMENT_NODE"; break;
    case Node.DOCUMENT_TYPE_NODE :
        retval = "DOCUMENT_TYPE_NODE"; break;
    case Node.ELEMENT_NODE :
        retval = "ELEMENT_NODE"; break;
    case Node.ENTITY_NODE :
        retval = "ENTITY_NODE"; break;
    case Node.ENTITY_REFERENCE_NODE :
        retval = "ENTITY_REFERENCE_NODE"; break;
    case Node.NOTATION_NODE :
        retval = "NOTATION_NODE"; break;
    case Node.PROCESSING_INSTRUCTION_NODE :
        retval = "PROCESSING_INSTRUCTION_NODE"; break;
    case Node.TEXT_NODE:
        retval = "TEXT_NODE"; break;
    }
    return retval;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:DOM2TO.java

示例7: getDocumentElement

/** This is a bit of a problem in DTM, since a DTM may be a Document
 * Fragment and hence not have a clear-cut Document Element. We can
 * make it work in the well-formed cases but would that be confusing for others?
 *
 *
 * @see org.w3c.dom.Document
 */
@Override
public final Element getDocumentElement()
{
              int dochandle=dtm.getDocument();
              int elementhandle=DTM.NULL;
              for(int kidhandle=dtm.getFirstChild(dochandle);
                              kidhandle!=DTM.NULL;
                              kidhandle=dtm.getNextSibling(kidhandle))
              {
                      switch(dtm.getNodeType(kidhandle))
                      {
                      case Node.ELEMENT_NODE:
                              if(elementhandle!=DTM.NULL)
                              {
                                      elementhandle=DTM.NULL; // More than one; ill-formed.
                                      kidhandle=dtm.getLastChild(dochandle); // End loop
                              }
                              else
                                      elementhandle=kidhandle;
                              break;

                      // These are harmless; document is still wellformed
                      case Node.COMMENT_NODE:
                      case Node.PROCESSING_INSTRUCTION_NODE:
                      case Node.DOCUMENT_TYPE_NODE:
                              break;

                      default:
                              elementhandle=DTM.NULL; // ill-formed
                              kidhandle=dtm.getLastChild(dochandle); // End loop
                              break;
                      }
              }
              if(elementhandle==DTM.NULL)
                      throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR);
              else
                      return (Element)(dtm.getNode(elementhandle));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:DTMNodeProxy.java

示例8: nodeSetMinusCommentNodes

/**
 * Recursively traverses the subtree, and returns an XPath-equivalent
 * node-set of all nodes traversed, excluding any comment nodes,
 * if specified.
 *
 * @param node the node to traverse
 * @param nodeSet the set of nodes traversed so far
 * @param the previous sibling node
 */
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
                                      Node prevSibling)
{
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            NamedNodeMap attrs = node.getAttributes();
            if (attrs != null) {
                for (int i = 0, len = attrs.getLength(); i < len; i++) {
                    nodeSet.add(attrs.item(i));
                }
            }
            nodeSet.add(node);
            Node pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.DOCUMENT_NODE :
            pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE:
            // emulate XPath which only returns the first node in
            // contiguous text/cdata nodes
            if (prevSibling != null &&
                (prevSibling.getNodeType() == Node.TEXT_NODE ||
                 prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
                return;
            }
            nodeSet.add(node);
            break;
        case Node.PROCESSING_INSTRUCTION_NODE :
            nodeSet.add(node);
            break;
        case Node.COMMENT_NODE:
            if (withComments) {
                nodeSet.add(node);
            }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:57,代码来源:DOMSubTreeData.java

示例9: dispatchNodeData

/**
   * 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.
   * <p>
   * %REVIEW% Note that as a DOM-level operation, it can be argued that this
   * routine _shouldn't_ perform any processing beyond what the DOM already
   * does, and that whitespace stripping and so on belong at the DTM level.
   * If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM.
   *
   * @param node Node whose subtree is to be walked, gathering the
   * contents of all Text or CDATASection nodes.
   */
  protected static void dispatchNodeData(Node node,
                                         org.xml.sax.ContentHandler ch,
                                         int depth)
            throws org.xml.sax.SAXException
  {

    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())
      {
        dispatchNodeData(child, ch, depth+1);
      }
    }
    break;
    case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW%
    case Node.COMMENT_NODE :
      if(0 != depth)
        break;
        // NOTE: Because this operation works in the DOM space, it does _not_ attempt
        // to perform Text Coalition. That should only be done in DTM space.
    case Node.TEXT_NODE :
    case Node.CDATA_SECTION_NODE :
    case Node.ATTRIBUTE_NODE :
      String str = node.getNodeValue();
      if(ch instanceof CharacterNodeHandler)
      {
        ((CharacterNodeHandler)ch).characters(node);
      }
      else
      {
        ch.characters(str.toCharArray(), 0, str.length());
      }
      break;
//    /* case Node.PROCESSING_INSTRUCTION_NODE :
//      // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
//      break; */
    default :
      // ignore
      break;
    }
  }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:DOM2DTM.java

示例10: hasTextContent

final boolean hasTextContent(Node child) {
    return child.getNodeType() != Node.COMMENT_NODE &&
        child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE &&
        (child.getNodeType() != Node.TEXT_NODE ||
         ((TextImpl) child).isIgnorableWhitespace() == false);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:ParentNode.java

示例11: nodeSetMinusCommentNodes

/**
 * Recursively traverses the subtree, and returns an XPath-equivalent
 * node-set of all nodes traversed, excluding any comment nodes,
 * if specified.
 *
 * @param node the node to traverse
 * @param nodeSet the set of nodes traversed so far
 * @param the previous sibling node
 */
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
                                      Node prevSibling)
{
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            nodeSet.add(node);
            NamedNodeMap attrs = node.getAttributes();
            if (attrs != null) {
                for (int i = 0, len = attrs.getLength(); i < len; i++) {
                    nodeSet.add(attrs.item(i));
                }
            }
            Node pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.DOCUMENT_NODE :
            pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE:
            // emulate XPath which only returns the first node in
            // contiguous text/cdata nodes
            if (prevSibling != null &&
                (prevSibling.getNodeType() == Node.TEXT_NODE ||
                 prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
                return;
            }
            nodeSet.add(node);
            break;
        case Node.PROCESSING_INSTRUCTION_NODE :
            nodeSet.add(node);
            break;
        case Node.COMMENT_NODE:
            if (withComments) {
                nodeSet.add(node);
            }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:57,代码来源:ReferenceSubTreeData.java

示例12: validate

boolean validate(String fn, KeySelector ks, URIDereferencer ud,
    boolean cache) throws Exception {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);
    Document doc = dbf.newDocumentBuilder().parse(new File(dir, fn));
    NodeList nl =
        doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    if (nl.getLength() == 0) {
        throw new Exception("Couldn't find signature Element");
    }
    Element sigElement = (Element) nl.item(0);
    DOMValidateContext vc = new DOMValidateContext(ks, sigElement);
    vc.setBaseURI(dir.toURI().toString());
    if (cache) {
        vc.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
    }
    XMLSignatureFactory factory = XMLSignatureFactory.getInstance();
    XMLSignature signature = factory.unmarshalXMLSignature(vc);
    if (ud != null) {
        vc.setURIDereferencer(ud);
    }
    boolean coreValidity = signature.validate(vc);

    // Check reference cache
    if (cache) {
        Iterator<Reference> i =
            signature.getSignedInfo().getReferences().iterator();
        for (int j = 0; i.hasNext(); j++) {
            Reference ref = i.next();
            if (!digestInputEqual(ref)) {
                throw new Exception
                    ("cached data for Reference[" + j + "] is not correct");
            }
            // check that dereferenced data does not contain comment nodes
            if (ref.getURI() == "") {
                System.out.println("checking deref data");
                @SuppressWarnings("unchecked")
                NodeSetData<Node> data =
                    (NodeSetData<Node>)ref.getDereferencedData();
                for (Node n : data) {
                    if (n.getNodeType() == Node.COMMENT_NODE) {
                        throw new Exception("dereferenced data for " +
                            " Reference[" + j + " contains comment node");
                    }
                }
            }
        }
    }
    return coreValidity;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:SignatureValidator.java

示例13: isGeneratedNode

private static boolean isGeneratedNode(Node node) {
    boolean rc = false;

    if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        String id = element.getAttribute("id"); //$NON-NLS-1$
        if (id != null) {
            for (String prefix : MergeConstants.OLD_XML_ELEMENT_PREFIXES) {
                if (id.startsWith(prefix)) {
                    rc = true;
                    break;
                }
            }
        }

        if (rc == false) {
            // check for new node format - if the first non-whitespace node
            // is an XML comment, and the comment includes
            // one of the old element tags,
            // then it is a generated node
            NodeList children = node.getChildNodes();
            int length = children.getLength();
            for (int i = 0; i < length; i++) {
                Node childNode = children.item(i);
                if (isWhiteSpace(childNode)) {
                    continue;
                } else if (childNode.getNodeType() == Node.COMMENT_NODE) {
                    Comment comment = (Comment) childNode;
                    String commentData = comment.getData();
                    for (String tag : MergeConstants.OLD_ELEMENT_TAGS) {
                        if (commentData.contains(tag)) {
                            rc = true;
                            break;
                        }
                    }
                } else {
                    break;
                }
            }
        }
    }

    return rc;
}
 
开发者ID:xiachengwei5,项目名称:org.mybatis.generator.core-1.3.5,代码行数:44,代码来源:XmlFileMergerJaxp.java

示例14: isCommentType

final boolean isCommentType() {
    return dom.getNodeType() == Node.COMMENT_NODE;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:3,代码来源:XmlNode.java

示例15: writeAnyNode

/**
 * Write any node.
 *
 * @param node
 *            the node
 * @throws ShellException
 *             the shell exception
 */
protected void writeAnyNode(Node node) throws ShellException {
    // is there anything to do?
    if (node == null) {
        return;
    }

    short type = node.getNodeType();
    switch (type) {
    case Node.DOCUMENT_NODE:
        write((Document) node);
        break;

    case Node.DOCUMENT_TYPE_NODE:
        write((DocumentType) node);
        break;

    case Node.ELEMENT_NODE:
        write((Element) node);
        break;

    case Node.ENTITY_REFERENCE_NODE:
        write((EntityReference) node);
        break;

    case Node.CDATA_SECTION_NODE:
        write((CDATASection) node);
        break;

    case Node.TEXT_NODE:
        write((Text) node);
        break;

    case Node.PROCESSING_INSTRUCTION_NODE:
        write((ProcessingInstruction) node);
        break;

    case Node.COMMENT_NODE:
        write((Comment) node);
        break;

    default:
        throw new ShellException(getString(
                "RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
    }
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:53,代码来源:DomWriter.java


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