Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将具有相同标记的xml结构解组到不同字段_Java_Jaxb - Fatal编程技术网

Java 将具有相同标记的xml结构解组到不同字段

Java 将具有相同标记的xml结构解组到不同字段,java,jaxb,Java,Jaxb,我必须阅读和编写XML文档,如: <connections> <connection> <operation>add</operation> <node>A01</node> <interface>AIF01</interface> <node>B01</node> <interface>BIF01</interfa

我必须阅读和编写XML文档,如:

<connections>
  <connection>
    <operation>add</operation>
    <node>A01</node>
    <interface>AIF01</interface>
    <node>B01</node>
    <interface>BIF01</interface>
  </connection>
<connection>
    <operation>delete</operation>
    <node>A02</node>
    <interface>AIF02</interface>
    <node>B02</node>
    <interface>BIF02</interface>
</connection>
因此,当我解组这样一个xml文件时,
targetNode
targetInterface
为空,因为它映射到
source*
字段

有人能帮忙吗?
提前谢谢。

您提到编组工作很好。。。但是如果有两个属性映射到一个XmlElement。。。哪一个正在使用?它是否可以正常工作,因为在这两种情况下都对源*字段进行编组和反编组?在任何情况下,您可能都可以使用事件处理程序方法,如
afterUnmarshall
,来完成您所期望的任务。因此
sourceNode
targetNode
使用相同的标记
。这种方法工作得很好,但是可以肯定,如果解组需要另一个实现,我必须更改实现,以便解组和编组工作。但怎么办?:-)
    @XmlElement(name = "connection")
    List<Connection> connections;
@XmlAccessorType(XmlAccessType.FIELD)
public class Connection {

  @XmlElement(name = "operation")
  private Operation operation;
  @XmlElement(name = "node")
  private String sourceNode;
  @XmlElement(name = "interface")
  private String sourceInterface;
  @XmlElement(name = "node")
  private String targetNode;
  @XmlElement(name = "interface")
  private String targetInterface;
}