如何将xml内容作为字符串传递给jaxb解析器

时间:2018-06-02 04:44:36

标签: xml-parsing

我有一个xml内容作为字符串如何将其传递给jaxb解析器以填充pojo类

<?xml version="1.0" encoding="UTF-8"?><breakfast_menu<food>
    <name>Belgian Waffles</name><food>

1 个答案:

答案 0 :(得分:0)

要传递XML内容,您需要将内容包装在Reader中,然后将其解组:

JAXBContext jaxbContext = JAXBContext.newInstance(Person.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

StringReader reader = new StringReader(&#34; xml string here&#34;); 人人=(人)unmarshaller.unmarshal(读者);