JAXB - 将元素解析为字符串 [英] JAXB - Parse element into string

查看:132
本文介绍了JAXB - 将元素解析为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将XML消息的一部分解析为String,保持XML格式?

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

示例...

<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 {
  ...
}

我希望整个地址元素以XML格式保存并解析为字符串。

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

推荐答案

您可以将@XmlAnyElement与DomHandler一起使用:

You can use @XmlAnyElement with a DomHandler:

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

这篇关于JAXB - 将元素解析为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆