List of usage examples for org.dom4j Node selectNodes
List<Node> selectNodes(String xpathExpression);
selectNodes
evaluates an XPath expression and returns the result as a List
of Node
instances or String
instances depending on the XPath expression.
From source file:us.wthr.jdem846.shapefile.modeling.ShapeDataDefinitionLoader.java
License:Apache License
public static List<ShapeDataDefinition> loadShapeDataDefinition() throws Exception { List<ShapeDataDefinition> shapeDataDefinitions = new LinkedList<ShapeDataDefinition>(); log.info("Loading shape data definitions from " + DEFAULT_XML_FILE); Document doc = loadDocument(DEFAULT_XML_FILE); ShapeDataDefinition shapeDataDefinition = null; List<?> shapeDataDefinitionList = doc.selectNodes("//jdem846/shape-types/shape-type"); for (Iterator<?> iter = shapeDataDefinitionList.iterator(); iter.hasNext();) { Node shapeDataDefinitionNode = (Node) iter.next(); Node nameAttribute = shapeDataDefinitionNode.selectSingleNode("@name"); Node idAttribute = shapeDataDefinitionNode.selectSingleNode("@id"); shapeDataDefinition = new ShapeDataDefinition(nameAttribute.getText(), idAttribute.getText()); Node featureTypeColumnNode = shapeDataDefinitionNode.selectSingleNode("featureTypeColumn"); if (featureTypeColumnNode != null) { Node featureTypeDefinitionIdNode = featureTypeColumnNode.selectSingleNode("@definition"); String featureTypeColumn = featureTypeColumnNode.getText(); shapeDataDefinition.setFeatureTypeDefinitionId(featureTypeDefinitionIdNode.getText()); shapeDataDefinition.setFeatureTypeColumn(featureTypeColumn); }/* w w w. j a v a 2 s .c o m*/ List<?> columnList = shapeDataDefinitionNode.selectNodes("columns/column"); for (Iterator<?> columnIter = columnList.iterator(); columnIter.hasNext();) { Node columnNode = (Node) columnIter.next(); Node columnNameNode = columnNode.selectSingleNode("@name"); shapeDataDefinition.addColumn(columnNameNode.getText(), columnNode.getText()); } shapeDataDefinitions.add(shapeDataDefinition); } return shapeDataDefinitions; }