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

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

I\'ve an xml which looks like this:

{ .....         


        
6条回答
  •  温柔的废话
    2020-12-03 14:32

    public static void main(String[] args) throws IOException {
        String filePath = "/Users/myXml/VH181.xml";
        File xmlFile = new File(filePath);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder;
        try {
            dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(xmlFile);
            doc.getDocumentElement().normalize();
            printElement(doc);
            System.out.println("XML file updated successfully");
        } catch (SAXException | ParserConfigurationException e1) {
            e1.printStackTrace();
        }
    }
    private static void printElement(Document someNode) {
        NodeList nodeList = someNode.getElementsByTagName("choiceInteraction");
        for(int z=0,size= nodeList.getLength();z

    we Can try this code using method

提交回复
热议问题