How to read an XML file with Java?

后端 未结 9 2137
执念已碎
执念已碎 2020-12-03 12:15

I don\'t need to read complex XML files. I just want to read the following configuration file with a simplest XML reader


    loc         


        
相关标签:
9条回答
  • 2020-12-03 12:58

    You could use a simple DOM parser to read the xml representation.

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    
    DocumentBuilder db = dbf.newDocumentBuilder();
    dom = db.parse("config.xml");
    
    0 讨论(0)
  • 2020-12-03 13:03

    I like jdom:

    SAXBuilder parser = new SAXBuilder();
    Document docConfig = parser.build("config.xml");
    Element elConfig = docConfig.getRootElement();
    String host = elConfig.getChildText("host");
    
    0 讨论(0)
  • 2020-12-03 13:05

    If you want to be able to read and write objects to XML directly, you can use XStream

    0 讨论(0)
提交回复
热议问题