Dom4J-SaxReader 的用法(具体参考hibernate3的源代码)

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" )

 

你可能感兴趣的:(Java资料)