Convert xml file to json object using dom parser in java

后端 未结 2 1272
死守一世寂寞
死守一世寂寞 2021-01-28 09:13

Trying to convert any type of XML file to JSON object structure . Different xml files are having varied depths of elements and sub-elements. creation of arrays when elements wit

2条回答
  •  礼貌的吻别
    2021-01-28 10:00

    Please refere this

    XmlMapper xmlMapper = new XmlMapper();

    String xml= FileUtils.readFileToString(new File("test_4.xsd.xml"),Charset.defaultCharset());

    JsonNode node = xmlMapper.readTree(xml.getBytes());

    ObjectMapper jsonMapper = new ObjectMapper();

    String json = jsonMapper.writeValueAsString(node);

    System.out.println(json);

提交回复
热议问题