Java XML Node Text Value hasOnlyTextSiblings(@Nonnull Node node)

Here you can find the source of hasOnlyTextSiblings(@Nonnull Node node)

Description

has Only Text Siblings

License

Apache License

Declaration

public static boolean hasOnlyTextSiblings(@Nonnull Node node) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.*;
import javax.annotation.Nonnull;

public class Main {
    public static boolean hasOnlyTextSiblings(@Nonnull Node node) {
        Node leftSibling = node.getPreviousSibling();

        while (leftSibling != null) {
            if (!(leftSibling instanceof Text)) {
                return false;
            }//w  ww . j  av a 2 s. co m

            leftSibling = leftSibling.getPreviousSibling();
        }

        Node rightSibling = node.getNextSibling();

        while (rightSibling != null) {
            if (!(rightSibling instanceof Text)) {
                return false;
            }

            rightSibling = rightSibling.getNextSibling();
        }

        return true;
    }
}

Related

  1. getTextValue(Node node)
  2. getTextValue(Node node)
  3. getTrimmedText (final Node node)
  4. getTrimmedTextContent(Node element)
  5. hasNodeText(Node n)
  6. hasTextContent(final Node node)
  7. hasTextContent(Node n)