JAXB应该忽略元素 [英] JAXB should ignore element

查看:86
本文介绍了JAXB应该忽略元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结构

<html>
   <span><h1>test</h1></span>
   <table>

   </table>
</html>

如果< span> <我如何获得文本test / code>可能是< div>

@XmlAccessorType(XmlAccessType.FIELD)
public class HtmlTag {
    @XmlElement(name = "h1")
    String h1;
}

Unmarshalls为null。

Unmarshalls to null.

推荐答案

@XmlAccessorType(XmlAccessType.FIELD)
public class HtmlTag 
{
    @XmlAnyElement
    List<org.w3c.dom.Element> elements;
}  

获取测试字符串

HtmlTag htmlTag = //...  
Element firstElement = htmlTag.elements.get(0); // this is first element,
                                        // currently it is <span>
firstElement.getElementsByTagName("h1").item(0).getTextContent(); // return 'test'

这篇关于JAXB应该忽略元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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