dom4j--SAXReader

1.创建对象
/**
* Create a dom4j SAXReader which will append all validation errors
* to errorList
*/
public SAXReader createSAXReader(String file, List errorsList, EntityResolver entityResolver) {
  if (saxReader==null) saxReader = new SAXReader();
  saxReader.setEntityResolver(entityResolver);
  saxReader.setErrorHandler( new ErrorLogger(file, errorsList) );
  saxReader.setMergeAdjacentText(true);
  saxReader.setValidation(true);
  return saxReader;
}

2.创建doc对象

org.dom4j.Document doc = xmlHelper.createSAXReader( xmlFile, errors, entityResolver ).read( new File(

xmlFile ) );


3.得到root节点

final Element hmNode = doc.getRootElement();

4.返回其他节点

subclasses[0] = hmNode.elementIterator( "subclass" );

5。返回全部节点
Iterator elements = sfNode.elementIterator();


6.返回节点的属性
element.attributeValue( "extends" )


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/babydavic/archive/2006/05/22/749557.aspx

你可能感兴趣的:(reader)