
if(child.getNodeName().equals(“price”))
{
String st = getText(child);
price = Double.valueOf(st).doubleValue();
price *= rate;
}
else if(child.getNodeName().equals(“name”))
name = getText(child);
}
}
System.out.println(name + “: “ + price);
}
}
protected static String getText(Node node)
{
Node child = node.getFirstChild();
if(child != null && child.getNodeType() == Node.TEXT_NODE)
{
Text text = (Text)child;
return text.getData();
}
else
return null;
}
}
Two Major Differences
1. The major difference between the Java and the JavaScript versions
is that Java properties have the form
getPropertyName().
Therefore, the following JavaScript code
if(node.nodeName == “product”) ...