Here you can find the source of getPreviousComment(Node element)
Parameter | Description |
---|---|
element | the element |
public static String getPreviousComment(Node element)
//package com.java2s; import org.w3c.dom.Node; public class Main { /**//from ww w . j a v a2 s . co m * Gets the previous comment. * * @param element * the element * @return the previous comment */ public static String getPreviousComment(Node element) { while (element.getPreviousSibling() != null) { Node prev = element.getPreviousSibling(); if (prev.getNodeType() == Node.COMMENT_NODE) { return prev.getTextContent(); } else if (prev.getNodeType() == Node.TEXT_NODE) { return getPreviousComment(prev); } else if (prev.getNodeType() == Node.ELEMENT_NODE) { return null; } } return null; } }