小编Nag*_*sam的帖子

XML(带命名空间)到对象解组

我从 Web 服务调用中得到了以下响应,我尝试使用 JAXB 对其进行解组以将其映射到 Java 类。这样做时我遇到了解组异常。

<?xml version="1.0" encoding="UTF-8"?>
<ns0:QueryByLNResponse xmlns:ns0="UIS_CTMPeople_WS" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ns0:getListValues>
        <ns0:First_Name>Pradeep</ns0:First_Name>
        <ns0:Internet_E-mail/>
        <ns0:ManagersName/>
        <ns0:Person_ID>PPL1</ns0:Person_ID>
        <ns0:Last_Name>Srinivasa Reddy</ns0:Last_Name>
        <ns0:Full_Name>Pradeep M Srinivasa Reddy</ns0:Full_Name>
    </ns0:getListValues>
    <ns0:getListValues>
        <ns0:First_Name>Geeth </ns0:First_Name>
        <ns0:Internet_E-mail>bas@yahoo.com</ns0:Internet_E-mail>
        <ns0:ManagersName/>
        <ns0:Person_ID>PPL2</ns0:Person_ID>
        <ns0:Last_Name>Srinivasan</ns0:Last_Name>
        <ns0:Full_Name>Geeth  Srinivasan</ns0:Full_Name>
    </ns0:getListValues>
</ns0:QueryByLNResponse>
Run Code Online (Sandbox Code Playgroud)

我尝试使用解组上述代码

public static Object xmlToObject(String xml, Class... objClass) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(objClass);
    final Unmarshaller unmarshaller = jc.createUnmarshaller();
    return unmarshaller.unmarshal(new StringReader(xml.toString()));
}
Run Code Online (Sandbox Code Playgroud)

它抛出以下错误

javax.xml.bind.UnmarshalException: unexpected element (uri:"UIS_CTMPeople_WS", local:"QueryByLNeResponse"). Expected elements are (none)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Unknown …
Run Code Online (Sandbox Code Playgroud)

namespaces jaxb unmarshalling

5
推荐指数
1
解决办法
1万
查看次数

IBM MQ-如何使用多个连接名称连接到队列管理器(一个已故障转移)

我对IBM MQ来说是新手。我的是一个多实例队列管理器。

一个实例就像故障转移。

即使其中之一发生故障,如何连接它们。

我不确定我的术语是否正确?

我正在尝试使用下面的示例进行连接

https://raw.githubusercontent.com/ibm-messaging/mq-dev-samples/master/gettingStarted/jms/JmsPutGet.java

jms spring-jms ibm-mq

2
推荐指数
1
解决办法
199
查看次数

标签 统计

ibm-mq ×1

jaxb ×1

jms ×1

namespaces ×1

spring-jms ×1

unmarshalling ×1