How do I map the inner text content of an element

2019-05-26 13:50发布

Say I have the following XML and Java code respectively:

<foo>
My text content
</foo>
@XmlRootElement( name="foo" )
public static class Foo
{
  // This is where I want to see "My text content" stored
  private String text;

  // getters and setters
}

When I tried marshalling the XML, my Foo instance doesn't get its text property populated with value from the inner text of my foo element in the given XML. How do I solve this?

1条回答
Bombasti
2楼-- · 2019-05-26 13:59

You can use the @XmlValue annotation.

@XmlValue 
public String getText() {
    return text;
}

For More Information

查看更多
登录 后发表回答