Please print the dependency tree of a XML document and  the level of each element in the XML. for examples:
 
<person id="0" name="james" title="manager">
    <person id="1" name="alex">
        <person id="2" name="flex">
            <person id="3" name="cathy"/>
        </person>
        <person id="4" name="john"/>   
    </person>
</person>
 
The result will be:
 
james(0)
`-- alex(1)
    |-- flex(2)
    |   `-- cathy(3)
    `-- john(2)
 
You can use the 3rd-party library (eg. libxml2 or java) . Graphics interface is preferred.
帮助我解决一下   感激不尽!谢谢

解决方案 »

  1.   

    不就是读取xml文件吗?
    参考代码package com; 
    import org.w3c.dom.*;
    import javax.xml.parsers.*;
    import java.io.*;public class Parse{
     //Document可以看作是XML在内存中的一个镜像,那么一旦获取这个Document 就意味着可以通过对
     //内存的操作来实现对XML的操作,首先第一步获取XML相关的Document
      private Document doc=null;
      
     public void init(String xmlFile) throws Exception{
      //很明显该类是一个单例,先获取产生DocumentBuilder工厂
      //的工厂,在通过这个工厂产生一个DocumentBuilder,
      //DocumentBuilder就是用来产生Document的
      DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
      DocumentBuilder db=dbf.newDocumentBuilder();  
      //这个Document就是一个XML文件在内存中的镜像
      doc=db.parse(new File(xmlFile));
     }
     //该方法负责把XML文件的内容显示出来
     public void viewXML(String xmlFile) throws Exception{
      this.init(xmlFile);
      //在xml文件里,只有一个根元素,先把根元素拿出来看看
      Element element=doc.getDocumentElement();
      System.out.println("根元素为:"+element.getTagName());
      
      NodeList nodeList=doc.getElementsByTagName("dbstore");
      System.out.println("dbstore节点链的长度:"+nodeList.getLength());
      
      Node fatherNode=nodeList.item(0);
      System.out.println("父节点为:"+fatherNode.getNodeName());
      
      //把父节点的属性拿出来
      NamedNodeMap attributes=fatherNode.getAttributes();
      
      for(int i=0;i<attributes.getLength();i++){
       Node attribute=attributes.item(i);
       System.out.println("dbstore的属性名为:"+attribute.getNodeName()+" 相对应的属性值为:"+attribute.getNodeValue());
      }  NodeList childNodes = fatherNode.getChildNodes();
      System.out.println(childNodes.getLength());
      for(int j=0;j<childNodes.getLength();j++){
       Node childNode=childNodes.item(j);
       //如果这个节点属于Element ,再进行取值
       if(childNode instanceof Element){
        //System.out.println("子节点名为:"+childNode.getNodeName()+"相对应的值为"+childNode.getFirstChild().getNodeValue());
        System.out.println("子节点名为:"+childNode.getNodeName()+"相对应的值为"+childNode.getFirstChild().getNodeValue());
       }
      }
      
     }
     
     public static void main(String[] args)throws Exception{
      Parse parse=new Parse();//我的XML文件
      parse.viewXML("netct.xml");
     }
    }  
      

  2.   

    做成这种效果
    james(0) 
    `-- alex(1) 
        |-- flex(2) 
        |  `-- cathy(3) 
        `-- john(2) 
    应该要涉及swing
      

  3.   

    You can use the 3rd-party library (eg. libxml2 or java) . Graphics interface is preferred. 
    这句话什么意思?
    谢谢!
      

  4.   

    就是你能借助于第三方的工具,例如libxml2或者java,用任何一种你擅长的ui来展现结果