开发者

How to store attribute and value of a XML tag using XStream

开发者 https://www.devze.com 2023-04-11 18:33 出处:网络
I have the following XML file <?xml version=\"1.0\"?> <paths> <path action=\"M\">some/path</path>

I have the following XML file

<?xml version="1.0"?>
<paths>
    <path action="M">some/path</path>
    <path action="D">another/path</path>
</paths>

I am trying to read it using the following classes:

public class Paths {
    @XStreamImplicit(itemFieldName="path")
    private ArrayList<Path> paths;  
}

@XStreamAlia开发者_如何学运维s("path")
public class Path {
    String path;
    @XStreamAsAttribute
    private String action;
}

The value of 'action' (Path.action) is really stored. But I only get NULL for the Path.path variable.

Any ideas of what I might have done wrong?


try ToAttributedValueConverter:

@XStreamAlias("path")
@XStreamConverter(value=ToAttributedValueConverter.class, strings={"path"})
public class Path {
  String path;
  String action;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号