JMS消息解析异常

时间:2013-08-17 10:25:50

标签: java xml parsing jms sax

我的java代码从我的本地ActiveMQ队列中获取XML消息。现在它可以成功使用队列中的消息,但似乎无法解析它?我的xml数据如下所示:

 #---------- #1 :  ----------#
 <MSG_INFO>
    <message type="TextMessage" messageSelector="" originationTimestamp="" receiveTime="" jmsServerTimestamp="" jmsMsgExpiration="">
     <header JMSDestination="Asurion.SYD02.Q.Business.NonPersistent.Policy.PublishTelstraAMAEnrollments" JMSDestinationType="Queue" JMSDeliveryMode="1" />
        <properties>
        <property name="Client" type="String">Telstra</property>
       </properties>
    </message>
 </MSG_INFO>
 BodyLength=850
 <?xml version="1.0" encoding="UTF-8"?>
 <ns0:PublishEnrollmentRequest xmlns:ns0="http://services.asurion.com/schemas/PolicyAdministration/PublishEnrollmentRequest/1.0">
  <ns0:Parameters>
    <ns0:Enrollments>
        <ns0:MDN>9890667692</ns0:MDN>
        <ns0:FeatureCode>MBBPHPMPS</ns0:FeatureCode>
        <ns0:ProductName>MTS-SA</ns0:ProductName>
        <ns0:Status>Active</ns0:Status>
        <ns0:Active>Y</ns0:Active>
        <ns0:EffectiveDate>2013-07-02T19:36:51-04:00</ns0:EffectiveDate>
        <ns0:EnrollmentType>Customer</ns0:EnrollmentType>
        <ns0:Make>UnKnown</ns0:Make>
        <ns0:Model>UnKnown</ns0:Model>
        <ns0:ActivationDate>2013-07-02T19:36:51-04:00</ns0:ActivationDate>
        <ns0:ESN />
        <ns0:IMEI />
        <ns0:SubID>281474977839805</ns0:SubID>
        <ns0:Operation>Enrollment Added</ns0:Operation>
    </ns0:Enrollments>
</ns0:Parameters>

我现在得到的例外是:

  Caused by: org.xml.sax.SAXParseException: Unexpected element: CDATA

我知道可能是BodyLength可能导致这个问题,但如果我摆脱它们,我的代码将无法从中提取客户信息。

这是可以在代码中配置的吗?感谢。

2 个答案:

答案 0 :(得分:1)

您的数据不是well-formed XML,并且无法按原样使用XML解析器进行解析。您必须找到一种方法来分隔BodyLength=850行之前和之后的XML数据并单独解析它们。

答案 1 :(得分:0)

如果可以,请尝试将xml更改为以下内容:

<?xml version="1.0" encoding="UTF-8"?>
 <ns0:PublishEnrollmentRequest xmlns:ns0="http://services.asurion.com/schemas/PolicyAdministration/PublishEnrollmentRequest/1.0">
  <ns0:Parameters>
    <ns0:Enrollments>
        <ns0:MDN>9890667692</ns0:MDN>
        <ns0:FeatureCode>MBBPHPMPS</ns0:FeatureCode>
        <ns0:ProductName>MTS-SA</ns0:ProductName>
        <ns0:Status>Active</ns0:Status>
        <ns0:Active>Y</ns0:Active>
        <ns0:EffectiveDate>2013-07-02T19:36:51-04:00</ns0:EffectiveDate>
        <ns0:EnrollmentType>Customer</ns0:EnrollmentType>
        <ns0:Make>UnKnown</ns0:Make>
        <ns0:Model>UnKnown</ns0:Model>
        <ns0:ActivationDate>2013-07-02T19:36:51-04:00</ns0:ActivationDate>
        <ns0:ESN />
        <ns0:IMEI />
        <ns0:SubID>281474977839805</ns0:SubID>
        <ns0:Operation>Enrollment Added</ns0:Operation>
    </ns0:Enrollments>
</ns0:Parameters>
 <MSG_INFO>
    <message type="TextMessage" messageSelector="" originationTimestamp="" receiveTime="" jmsServerTimestamp="" jmsMsgExpiration="">
     <header JMSDestination="Asurion.SYD02.Q.Business.NonPersistent.Policy.PublishTelstraAMAEnrollments" JMSDestinationType="Queue" JMSDeliveryMode="1" />
        <properties>
        <property name="Client" type="String">Telstra</property>
       </properties>
    </message>
 </MSG_INFO>
 <body  BodyLength="850" />
</ns0:PublishEnrollmentRequest>

如果您不想更改xml,请尝试在BodyLength=850上方和下方分隔xml。并在文件开头使用<?xml version="1.0" encoding=utf-8"?>