0
這是我想要解組的XML(我沒有XSD)。我必須解開它才能得到一個名稱和Id的數組。所以,名字生成得很好,但問題在於Id。 Id的設置爲空。任何人都可以幫助我找出問題嗎?使用Moxy在複雜類型元素上獲取Null值JAXB
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" typeLanguage="http://www.w3.org/2001/XMLSchema">
<bpmn:collaboration id="Collaboration_0b6zt1k" isClosed="false">
<bpmn:participant id="Participant_113vq9r" processRef="CallActivity_00qe833" />
</bpmn:collaboration>
<bpmn:process id="CallActivity_00qe833" isClosed="false" isExecutable="true" name="Some Text" processType="None">
<bpmn:serviceTask activiti:class="Assign PC" completionQuantity="1" id="ServiceTask_0ip6tj7" implementation="##WebService" isForCompensation="false" name="Some Text 1" startQuantity="1">
<bpmn:extensionElements>
<activiti:properties>
<activiti:property name="specKey" value="ServiceTask_0ip6tj7" />
</activiti:properties>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_0sa9y9o</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1bd3qmp</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:serviceTask activiti:class="generateURL" completionQuantity="1" id="ServiceTask_11t11da" implementation="##WebService" isForCompensation="false" name="Some Text 2" startQuantity="1">
<bpmn:extensionElements>
<activiti:properties>
<activiti:property name="specKey" value="ServiceTask_11t11da" />
</activiti:properties>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_1bd3qmp</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0cynzzs</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:serviceTask activiti:class="generateURL" completionQuantity="1" id="ServiceTask_11t11da" implementation="##WebService" isForCompensation="false" name="Some Text 3" startQuantity="1">
<bpmn:extensionElements>
<activiti:properties>
<activiti:property name="specKey" value="ServiceTask_11t11da" />
</activiti:properties>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_1bd3qmp</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0cynzzs</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
</bpmn:definitions>
這是我的JAXB註解類:
package XMLToObject;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.oxm.annotations.XmlPath;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class definitions {
@XmlPath("bpmn:process/bpmn:serviceTask/@name")
@XmlAttribute
List<String> name;
@XmlPath("bpmn:process/bpmn:serviceTask/@id")
@XmlAttribute
List<String> id;
@XmlAttribute
String typeLanguage;
public List<String> getname() {
return name;
}
public List<String> getid() {
return id;
}
public String gettypeLanguage() {
return typeLanguage;
}
}
這是我的Java類:
package XMLToObject;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Gauravb
*/
import java.io.File;
import java.util.Collection;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class XMLToObject {
public static void main(String[] args) {
try {
File file = new File("employee.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(definitions.class);
System.out.println("JAXB....."+jaxbContext.toString());
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
definitions p = (definitions) jaxbUnmarshaller.unmarshal(file);
System.out.println("Task Name:"+p.getname());
System.out.println("Svc ID:"+p.getid());
System.out.println("Type Language:"+p.gettypeLanguage());
} catch (JAXBException e) {e.printStackTrace(); }
}
}
現在,這是我得到的輸出:
run:
[email protected]
Task Name:[Some Text 1, Some Text 2, Some Text 3]
Svc ID:null
Type Language:http://www.w3.org/2001/XMLSchema
BUILD SUCCESSFUL (total time: 0 seconds)
我的問題是,爲什麼我得到Svc ID爲「n üll「當同樣的工作任務名稱。
請注意: 1.我使用莫西爲JAXB 2.請注意,當我更改順序,然後名字越來越設置爲空:
@XmlPath("bpmn:process/bpmn:serviceTask/@id")
@XmlAttribute
List<String> id;
@XmlPath("bpmn:process/bpmn:serviceTask/@name")
@XmlAttribute
List<String> name;
我得到這樣的輸出:
run:
[email protected]
Task Name:null
Svc ID:[ServiceTask_0ip6tj7, ServiceTask_11t11da, ServiceTask_11t11da]
Type Language:http://www.w3.org/2001/XMLSchema
BUILD SUCCESSFUL (total time: 0 seconds)