|
|
@@ -53,11 +53,20 @@ final public class XMLQuery {
|
|
|
|
|
|
|
|
|
public static String attr(Node node, String attribName) throws XMLQueryException {
|
|
|
+ if(node == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
Node attrNode = node.getAttributes().getNamedItem(attribName);
|
|
|
- return attrNode == null ? null : attrNode.getNodeValue();
|
|
|
+ if(attrNode == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return attrNode.getNodeValue();
|
|
|
}
|
|
|
|
|
|
public static boolean has(Node node, String attribName) {
|
|
|
+ if(node == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
return null != node.getAttributes().getNamedItem(attribName);
|
|
|
}
|
|
|
|
|
|
@@ -91,6 +100,9 @@ final public class XMLQuery {
|
|
|
|
|
|
public static List<Node> filter(Node node, String tagname) {
|
|
|
List<Node> result = new LinkedList<Node>();
|
|
|
+ if(node == null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
for(Node value : NodeCollection.nodes(node) ) {
|
|
|
if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
|
|
|
result.add(value);
|
|
|
@@ -100,6 +112,9 @@ final public class XMLQuery {
|
|
|
}
|
|
|
|
|
|
public static Node node(Node node, String tagname) {
|
|
|
+ if(node == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
for(Node value : NodeCollection.nodes(node) ) {
|
|
|
if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
|
|
|
return value;
|
|
|
@@ -110,6 +125,9 @@ final public class XMLQuery {
|
|
|
|
|
|
public static List<Node> filter(Node node, NodeType type) {
|
|
|
List<Node> result = new LinkedList<Node>();
|
|
|
+ if(node == null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
for(Node value : NodeCollection.nodes(node) ) {
|
|
|
if( type.match(value.getNodeType()) ) {
|
|
|
result.add(value);
|
|
|
@@ -119,6 +137,9 @@ final public class XMLQuery {
|
|
|
}
|
|
|
|
|
|
public static int count(Node node, String tagname) {
|
|
|
+ if(node == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
int count = 0;
|
|
|
for(Node value : NodeCollection.nodes(node) ) {
|
|
|
if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
|
|
|
@@ -129,6 +150,9 @@ final public class XMLQuery {
|
|
|
}
|
|
|
|
|
|
public static int count(Node node, NodeType type) {
|
|
|
+ if(node == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
int count = 0;
|
|
|
for(Node value : NodeCollection.nodes(node) ) {
|
|
|
if( type.match(value) ) { count ++; }
|
|
|
@@ -141,6 +165,9 @@ final public class XMLQuery {
|
|
|
}
|
|
|
|
|
|
public static boolean exists(Node node, String tagname) {
|
|
|
+ if(node == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
for(Node value : NodeCollection.nodes(node) ) {
|
|
|
if( (Node.ELEMENT_NODE==value.getNodeType()) && tagname.equals(value.getNodeName()) ) {
|
|
|
return true;
|