Моя цель состоит в том, чтобы демонтировать XML-файл в один объект Java.
Мой XML выглядит так:
<root>
<info1>
<info2>
<info3>
<nested1>
<nested2>
<info4>
<info5>
<nested2>
<nested1>
<root>
Я получаю информацию только от info1-info3.
BusinessOperationEvent содержит все элементы XMLE из файла XML.
Класс парсера:
public class Parser {
public static void main(String[] args){
try {
ClassLoader classLoader = Parser.class.getClassLoader();
File xml = new File(classLoader.getResource("XML.xml").getFile());
JAXBContext jaxbContext = JAXBContext.newInstance(BusinessOperationEvent.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
BusinessOperationEvent event = (BusinessOperationEvent) unmarshaller.unmarshal(xml);
System.out.println(event);
} catch (JAXBException e) {
throw new RuntimeException("Error unmarshalling XML");
}
}
}
BusinessOperationEvent - объект Java для сбора информации из XML:
@XmlRootElement(name = "SrvPutBusinessOperationEventNf")
@XmlAccessorType(XmlAccessType.FIELD)
public class BusinessOperationEvent {
@XmlElement(name = "RqUID")
private String rqUID;
@XmlElement(name = "RqTm")
private String rqTm;
@XmlElement(name = "sPName")
private String sPName;
@XmlElement(name = "SystemId")
private String systemId;
@XmlElement(name = "Method")
private String method;
@XmlElement(name = "BusinessProcess")
private String businessProcess;
@XmlElement(name = "Operation")
private String operation;
@XmlElement(name = "Step")
private String step;
@XmlElement(name = "SourceModule")
private String sourceModule;
@XmlElement(name = "Id")
private String id;
@XmlElement(name = "EventDate")
private String eventDate;
@XmlElement(name = "SendDate")
private String sendDate;
@XmlElement(name = "ActionCallInfo")
private String actionCallInfo;
@XmlElement(name = "ActivityRepCallInfo")
private String activityRepCallInfo;
@XmlElement(name = "AccountEPKId")
private String accountEPKId;
@XmlElement(name = "AccountCRMId")
private String accountCRMId;
@XmlElement(name = "CallId")
private String сallId;
@XmlElement(name = "CalledFromNum")
private String calledFromNum;
@XmlElement(name = "AppealName")
private String appealName;
@XmlElement(name = "CallbackPhone")
private String callbackPhone;
@XmlElement(name = "EndDate")
private String endDate;
@XmlElement(name = "Comment")
private String comment;
@XmlElement(name = "Result")
private String result;
@XmlElement(name = "CreatorFullName")
private String creatorFullName;
@XmlElement(name = "EmployeeId")
private String employeeId;
@XmlElement(name = "CRMCCQuestionInfo")
private String crmccQuestionInfo;
@XmlElement(name = "ServiceRequestInfo")
private String serviceRequestInfo;
@XmlElement(name = "ActionMeetingInfo")
private String actionMeetingInfo;
@Override
public String toString() {
return "BusinessOperationEvent{" +
"rqUID='" + rqUID + '\'' +
", rqTm='" + rqTm + '\'' +
", sPName='" + sPName + '\'' +
", systemId='" + systemId + '\'' +
", method='" + method + '\'' +
", businessProcess='" + businessProcess + '\'' +
", operation='" + operation + '\'' +
", step='" + step + '\'' +
", sourceModule='" + sourceModule + '\'' +
", id='" + id + '\'' +
", eventDate='" + eventDate + '\'' +
", sendDate='" + sendDate + '\'' +
", actionCallInfo='" + actionCallInfo + '\'' +
", activityRepCallInfo='" + activityRepCallInfo + '\'' +
", accountEPKId='" + accountEPKId + '\'' +
", accountCRMId='" + accountCRMId + '\'' +
", сallId='" + сallId + '\'' +
", calledFromNum='" + calledFromNum + '\'' +
", appealName='" + appealName + '\'' +
", callbackPhone='" + callbackPhone + '\'' +
", endDate='" + endDate + '\'' +
", comment='" + comment + '\'' +
", result='" + result + '\'' +
", creatorFullName='" + creatorFullName + '\'' +
", employeeId='" + employeeId + '\'' +
", crmccQuestionInfo='" + crmccQuestionInfo + '\'' +
", serviceRequestInfo='" + serviceRequestInfo + '\'' +
", actionMeetingInfo='" + actionMeetingInfo + '\'' +
'}';
}
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<SrvPutBusinessOperationEventNf>
<RqUID>info</RqUID>
<RqTm>info</RqTm>
<SPName>info</SPName>
<SystemId>info</SystemId>
<Method></Method>
<Message>
<Event>
<BusinessProcess>info</BusinessProcess>
<Operation>info</Operation>
<Step>info</Step>
<SourceModule>info</SourceModule>
<Id>info</Id>
<EventDate>info</EventDate>
<SendDate>info</SendDate>
<BusinessAttributes>
<ActionCallInfo/>
<ActivityRepCallInfo/>
<CRMCCCallInfo>
<AccountEPKId>info</AccountEPKId>
<AccountCRMId>info</AccountCRMId>
<CallId>info</CallId>
<CalledFromNum>info</CalledFromNum>
<AppealName>info</AppealName>
<CallbackPhone>info</CallbackPhone>
<EndDate>info</EndDate>
<Comment>info</Comment>
<Result>info</Result>
<CreatorFullName>info</CreatorFullName>
<EmployeeId>info</EmployeeId>
</CRMCCCallInfo>
<CRMCCQuestionInfo/>
<ServiceRequestInfo/>
<ActionMeetingInfo/>
</BusinessAttributes>
</Event>
</Message>
</SrvPutBusinessOperationEventNf>
У меня в Java-объекте есть информация только по методу XML, а не только по нулям.