how to get the attribute value of an xml node using java

前端 未结 6 820
抹茶落季
抹茶落季 2020-12-03 13:59

I\'ve an xml which looks like this:

{ .....         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 14:29

    I'm happy that this snippet works fine:

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(new File("config.xml"));
    NodeList nodeList = document.getElementsByTagName("source");
    for(int x=0,size= nodeList.getLength(); x

提交回复
热议问题