Package org.w3c.dom.traversal

Examples of org.w3c.dom.traversal.DocumentTraversal


      return;
    }
   
    Document doc = (Document)model;
    try{
      DocumentTraversal traversal = (DocumentTraversal)doc;
      TreeWalker walker = traversal.createTreeWalker(doc.getDocumentElement(),NodeFilter.SHOW_ALL, null, true);
      writeDOM(walker,writer);
    }
    catch(Exception e){
      if (logger.isLoggable(Level.SEVERE)) {
                logger.log(Level.SEVERE, "Document not created ");
View Full Code Here


   * @return
   */
  private Node getParentNode(Node doc,String parent) {
    Node parentNode = null;
    try{
      DocumentTraversal traversal = (DocumentTraversal)doc;
     
      CharSequence prefixChar = ":";
      NodeIterator iterator = traversal.createNodeIterator(document.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
      for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
        String nodeName = n.getNodeName();
        String[] str = null;
        if(n.getNodeName().contains(prefixChar)){
          str = nodeName.split(":");
View Full Code Here

  public DOMSerializerEngine (Node root, String encoding) {
    this (getIterator (root), encoding);
  }

  private static NodeIterator getIterator (Node node) {
    DocumentTraversal dt = (DocumentTraversal)
      ((node instanceof DocumentTraversal) ? node : node.getOwnerDocument ());
    return dt.createNodeIterator (node, NodeFilter.SHOW_ALL, null, false);
 
View Full Code Here

    DocumentBuilder builder = parserFactory.newDocumentBuilder();
    return builder.parse(in);
  }
   
  private void removeWhiteSpace(Document document) throws Exception {
    DocumentTraversal dt = (DocumentTraversal) document;
    NodeIterator nodeIterator =
      dt.createNodeIterator(document, NodeFilter.SHOW_TEXT, null, true);
    Node node = nodeIterator.nextNode();
    while (node != null) {
      if (node.getNodeValue().trim().compareTo("") == 0) {
        node.getParentNode().removeChild(node);
      }
View Full Code Here

     * @param attrName name of attribute filter.
     * @param attrContains expected content for attribute.
     * @return
     */
    private static List<Node> findAllBy(Node root, final String tagName, final String attrName, String attrContains) {
        DocumentTraversal documentTraversal = (DocumentTraversal) root.getOwnerDocument();
        if (documentTraversal == null) {
            documentTraversal = (DocumentTraversal) root;
        }

        final Pattern attrContainsPattern;
        if (attrContains != null && !attrContains.equals("*")) {
            attrContainsPattern = Pattern.compile("(^|\\s)" + attrContains + "(\\s|$)", Pattern.CASE_INSENSITIVE);
        } else {
            attrContainsPattern = null;
        }

        final List<Node> result = new ArrayList<Node>();
        NodeIterator nodeIterator = documentTraversal.createNodeIterator(
                root,
                NodeFilter.SHOW_ELEMENT,
                new NodeFilter() {
                    @Override
                    public short acceptNode(Node node) {
View Full Code Here

        }

        private void parseDocument(Document dasDoc, String chr, List<Feature> features) {

            try {
                DocumentTraversal traversal = (DocumentTraversal) dasDoc;
                TreeWalker treewalker = traversal.createTreeWalker(
                        dasDoc.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
                parseTree(treewalker, "FEATURE", chr, features);

            } catch (Exception ex) {
                log.error(ex);
View Full Code Here

    {
        Document doc = null;
        Element root = null;

        // Using TreeWalker
        DocumentTraversal travDoc = (DocumentTraversal)doc;
        TreeWalker walker = travDoc.createTreeWalker(root,NodeFilter.SHOW_ELEMENT,null,true);
        Element child = (Element)walker.firstChild();
        while(child != null)
        {
            // Do something with child ...
            child = (Element)walker.nextSibling();
View Full Code Here

    document.appendChild(result);
    return document;
  }

  private void removeWhiteSpace(Node context) {
    DocumentTraversal traversal = context instanceof Document
            ? (DocumentTraversal) context
            : (DocumentTraversal) context.getOwnerDocument();
    NodeIterator nodeIterator = traversal.createNodeIterator(context, NodeFilter.SHOW_TEXT, null, true);
    Node node = nodeIterator.nextNode();
    while (node != null) {
      if (node.getNodeValue().trim().compareTo("") == 0) {
        node.getParentNode().removeChild(node);
      }
View Full Code Here

      }
      if (document instanceof OMDocument) {
    return ((OMDocument)document).getOMDocumentElement();
   
      } else {
    DocumentTraversal traversal = (DocumentTraversal) document;
    TreeWalker walker = traversal.createTreeWalker(
        ((Document)document).getDocumentElement(), NodeFilter.SHOW_ALL, null, true);
    return (OMElement) traverseDOMDocument(fac, walker, null);   
      }   
  }
View Full Code Here

      } else {
      try {
            Document doc =
               DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
                  input.getOctetStream());
            DocumentTraversal dt = ((DocumentTraversal) doc);
            Node rootNode = (Node) doc;

            // we accept all nodes
            NodeFilter nodefilter = new AlwaysAcceptNodeFilter();
            TreeWalker treewalker = dt.createTreeWalker(rootNode,
                                                        NodeFilter.SHOW_ALL,
                                                        nodefilter, true);
            StringBuffer sb = new StringBuffer();

            process(treewalker, sb);
View Full Code Here

TOP

Related Classes of org.w3c.dom.traversal.DocumentTraversal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.