JAXB - Parse element into string

帅比萌擦擦* 提交于 2020-01-16 04:33:08

问题


Is there a way to parse part of an XML message into a String keeping it in XML format?

Example...

<person>
  <name>John Doe</name>
  <age>24</age>

  <address>
    <street>bailey</street>
    <city>boston</city>
  </address>
</person>

public class Person {

  @XmlElement
  private NameClass name;

  @XmlElement
  private int age;

  @XmlElement
  private String address; 

  ...
}

public class NameClass {
  ...
}

Where I want the entire address element to be kept in XML format and parsed as a String.


回答1:


You can use @XmlAnyElement with a DomHandler:

  • http://blog.bdoughan.com/2011/04/xmlanyelement-and-non-dom-properties.html


来源:https://stackoverflow.com/questions/9040695/jaxb-parse-element-into-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!