/**
 * @author mvmouse
 */
public class JdomTest extends TestCase { private Document itsDom; //Dom
private Element itsRoot; //根节点 public void testGetContent()
{
try
{
this.InitFromStream( JdomTest.class
.getResourceAsStream( "test.xml" ) );
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
System.out.println( itsRoot.getName() );
List chindren = itsRoot.getChildren();
for (int i = 0; i < chindren.size(); i++)
{
Element tilte = (Element) chindren.get( i );
System.out.println( "\t"+tilte.getName() );

Element name = tilte.getChild( "Name" );
System.out.println( "\t\t"+name.getName() );

Element ad = name.getChild( "ad" );
System.out.println( "\t\t\t"+ad.getName() );
System.out.println( "\t\t\t\t"+ad.getText() );
}
} /**
 * 新建一个DOM对象
 * 
 * @param root
 *                DOM的根元素的名称
 */
public void createNewDom(String root)
{
try
{
itsDom = new Document();
itsRoot = new Element( root );
itsDom.setRootElement( itsRoot );
}
catch (Exception e)
{
e.printStackTrace();
}
} /**
 * 由输入流初始化DOM
 * 
 * @param is
 *                使用的输入流
 * @throws FileNotFoundException
 */
public void InitFromStream(InputStream is) throws FileNotFoundException
{
if (is != null)
{
try
{
SAXBuilder sb = new SAXBuilder();
//从文件构造一个Document
itsDom = sb.build( is );
itsRoot = itsDom.getRootElement();
}
catch (Exception e)
{
e.printStackTrace();
}
}
else
throw new FileNotFoundException();
}
}