I am trying to build a function which traverse a Dom tree if and only if the node name is not equal to script and style. here is the function:
public static void PostOrderTR(Node node) throws XPathExpressionException, MalformedURLException, SAXNotRecognizedException, SAXNotSupportedException, ParserConfigurationException, IOException, SAXException
{
if (node == null || node.getNodeName() == null)
{
return;
}
if(!"script".equals(node.getNodeName())||!"style".equals(node.getLocalName())|| !"style".equals(node.getNodeName()))
{
//do something
PostOrderTR(node.getFirstChild());
}
if(!"script".equals(node.getNodeName())||!"style".equals(node.getLocalName())|| !"style".equals(node.getNodeName()))
PostOrderTR(node.getNextSibling());
}
but in practice, it results exactly opposite. it goes through all nodes including the script and style. I already tried to replace&& with || and nothing changed much.
Your condition doesn't work because all node names are either not "script" or not "style", so all node names pass.
The right condition is :
if(!("script".equals(node.getNodeName())||"style".equals(node.getLocalName()))
This means that the node name is neither "script" nor "style".