我在分割使用名称空间的较大XML时遇到问题。
以下XML分为<tns:tradeStatusDetails>
:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<tns:customerResponse xmlns:tns="http://deutsche-boerse.com/DBRegHub" xsi:schemaLocation="http://deutsche-boerse.com/DBRegHub CustomerResponse001.20_inclESMAupdates.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:tradeStatusReport>
<tns:tradeStatusInformation>
<tns:responseType>Deutsche Börse Group - Regulatory Reporting Hub - Trade Status Report</tns:responseType>
<tns:customerId>549300GKFG0RYRRQ1414</tns:customerId>
<tns:senderId>529900G3SW56SHYNPR95</tns:senderId>
<tns:timestamp>2018-04-10T22:41:56.000000000</tns:timestamp>
<tns:environment>SIM</tns:environment>
<tns:version>001.20</tns:version>
<tns:totalRecords>6</tns:totalRecords>
</tns:tradeStatusInformation>
<tns:tradeStatusDetails>
<tns:submissionTimestamp>2018-04-10T14:22:22.096000000</tns:submissionTimestamp>
<tns:customerTransactionId>107902</tns:customerTransactionId>
<tns:referenceId>107902</tns:referenceId>
<tns:reportingObligationEntityId>549300GKFG0RYRRQ1414</tns:reportingObligationEntityId>
<tns:tradeDate>2018-04-10</tns:tradeDate>
<tns:reportLevel>T</tns:reportLevel>
<tns:actionType>N</tns:actionType>
<tns:regulation>MiFIR</tns:regulation>
<tns:recordVersion>1</tns:recordVersion>
<tns:userField1>1</tns:userField1>
<tns:lastUpdateTime>22:18:51.760</tns:lastUpdateTime>
<tns:lifecycleStatus>final</tns:lifecycleStatus>
<tns:dataUploadStatus>accepted</tns:dataUploadStatus>
<tns:immediateValidStatus>warning</tns:immediateValidStatus>
<tns:tradeReportMatchStatus>n/a</tns:tradeReportMatchStatus>
<tns:exchangeDataMatchStatus>n/a</tns:exchangeDataMatchStatus>
<tns:assistedReportingMatchStatus>open</tns:assistedReportingMatchStatus>
<tns:postEnrichmentStatus>n/a</tns:postEnrichmentStatus>
<tns:aggregatedValidStatus>warning</tns:aggregatedValidStatus>
<tns:ncaTrStatus>accepted</tns:ncaTrStatus>
<tns:ncaTrReconStatus>n/a</tns:ncaTrReconStatus>
<tns:senderArmReconStatus>n/a</tns:senderArmReconStatus>
</tns:tradeStatusDetails>
<tns:tradeStatusDetails>
<tns:submissionTimestamp>2018-04-10T14:22:22.096000000</tns:submissionTimestamp>
<tns:customerTransactionId>107903</tns:customerTransactionId>
<tns:referenceId>107903</tns:referenceId>
<tns:reportingObligationEntityId>549300GKFG0RYRRQ1414</tns:reportingObligationEntityId>
<tns:tradeDate>2018-04-10</tns:tradeDate>
<tns:reportLevel>T</tns:reportLevel>
<tns:actionType>N</tns:actionType>
<tns:regulation>MiFIR</tns:regulation>
<tns:recordVersion>1</tns:recordVersion>
<tns:userField1>1</tns:userField1>
<tns:lastUpdateTime>22:18:51.760</tns:lastUpdateTime>
<tns:lifecycleStatus>final</tns:lifecycleStatus>
<tns:dataUploadStatus>accepted</tns:dataUploadStatus>
<tns:immediateValidStatus>warning</tns:immediateValidStatus>
<tns:tradeReportMatchStatus>n/a</tns:tradeReportMatchStatus>
<tns:exchangeDataMatchStatus>n/a</tns:exchangeDataMatchStatus>
<tns:assistedReportingMatchStatus>open</tns:assistedReportingMatchStatus>
<tns:postEnrichmentStatus>n/a</tns:postEnrichmentStatus>
<tns:aggregatedValidStatus>warning</tns:aggregatedValidStatus>
<tns:ncaTrStatus>accepted</tns:ncaTrStatus>
<tns:ncaTrReconStatus>n/a</tns:ncaTrReconStatus>
<tns:senderArmReconStatus>n/a</tns:senderArmReconStatus>
</tns:tradeStatusDetails>
<tns:tradeStatusDetails>
<tns:submissionTimestamp>2018-04-10T14:22:22.096000000</tns:submissionTimestamp>
<tns:customerTransactionId>107904</tns:customerTransactionId>
<tns:referenceId>107904</tns:referenceId>
<tns:reportingObligationEntityId>549300GKFG0RYRRQ1414</tns:reportingObligationEntityId>
<tns:tradeDate>2018-04-10</tns:tradeDate>
<tns:reportLevel>T</tns:reportLevel>
<tns:actionType>N</tns:actionType>
<tns:regulation>MiFIR</tns:regulation>
<tns:recordVersion>1</tns:recordVersion>
<tns:userField1>1</tns:userField1>
<tns:lastUpdateTime>22:18:51.760</tns:lastUpdateTime>
<tns:lifecycleStatus>final</tns:lifecycleStatus>
<tns:dataUploadStatus>accepted</tns:dataUploadStatus>
<tns:immediateValidStatus>warning</tns:immediateValidStatus>
<tns:tradeReportMatchStatus>n/a</tns:tradeReportMatchStatus>
<tns:exchangeDataMatchStatus>n/a</tns:exchangeDataMatchStatus>
<tns:assistedReportingMatchStatus>open</tns:assistedReportingMatchStatus>
<tns:postEnrichmentStatus>n/a</tns:postEnrichmentStatus>
<tns:aggregatedValidStatus>warning</tns:aggregatedValidStatus>
<tns:ncaTrStatus>sent</tns:ncaTrStatus>
<tns:ncaTrReconStatus>n/a</tns:ncaTrReconStatus>
<tns:senderArmReconStatus>n/a</tns:senderArmReconStatus>
</tns:tradeStatusDetails>
<tns:tradeStatusDetails>
<tns:submissionTimestamp>2018-04-10T14:22:22.096000000</tns:submissionTimestamp>
<tns:customerTransactionId>107905</tns:customerTransactionId>
<tns:referenceId>107905</tns:referenceId>
<tns:reportingObligationEntityId>549300GKFG0RYRRQ1414</tns:reportingObligationEntityId>
<tns:tradeDate>2018-04-10</tns:tradeDate>
<tns:reportLevel>T</tns:reportLevel>
<tns:actionType>N</tns:actionType>
<tns:regulation>MiFIR</tns:regulation>
<tns:recordVersion>1</tns:recordVersion>
<tns:userField1>1</tns:userField1>
<tns:lastUpdateTime>22:18:51.760</tns:lastUpdateTime>
<tns:lifecycleStatus>final</tns:lifecycleStatus>
<tns:dataUploadStatus>accepted</tns:dataUploadStatus>
<tns:immediateValidStatus>warning</tns:immediateValidStatus>
<tns:tradeReportMatchStatus>n/a</tns:tradeReportMatchStatus>
<tns:exchangeDataMatchStatus>n/a</tns:exchangeDataMatchStatus>
<tns:assistedReportingMatchStatus>open</tns:assistedReportingMatchStatus>
<tns:postEnrichmentStatus>n/a</tns:postEnrichmentStatus>
<tns:aggregatedValidStatus>warning</tns:aggregatedValidStatus>
<tns:ncaTrStatus>sent</tns:ncaTrStatus>
<tns:ncaTrReconStatus>n/a</tns:ncaTrReconStatus>
<tns:senderArmReconStatus>n/a</tns:senderArmReconStatus>
</tns:tradeStatusDetails>
<tns:tradeStatusDetails>
<tns:submissionTimestamp>2018-04-10T14:22:22.096000000</tns:submissionTimestamp>
<tns:customerTransactionId>107906</tns:customerTransactionId>
<tns:referenceId>107906</tns:referenceId>
<tns:reportingObligationEntityId>549300GKFG0RYRRQ1414</tns:reportingObligationEntityId>
<tns:tradeDate>2018-04-10</tns:tradeDate>
<tns:reportLevel>T</tns:reportLevel>
<tns:actionType>N</tns:actionType>
<tns:regulation>MiFIR</tns:regulation>
<tns:recordVersion>1</tns:recordVersion>
<tns:userField1>1</tns:userField1>
<tns:lastUpdateTime>22:18:51.760</tns:lastUpdateTime>
<tns:lifecycleStatus>final</tns:lifecycleStatus>
<tns:dataUploadStatus>accepted</tns:dataUploadStatus>
<tns:immediateValidStatus>warning</tns:immediateValidStatus>
<tns:tradeReportMatchStatus>n/a</tns:tradeReportMatchStatus>
<tns:exchangeDataMatchStatus>n/a</tns:exchangeDataMatchStatus>
<tns:assistedReportingMatchStatus>open</tns:assistedReportingMatchStatus>
<tns:postEnrichmentStatus>n/a</tns:postEnrichmentStatus>
<tns:aggregatedValidStatus>warning</tns:aggregatedValidStatus>
<tns:ncaTrStatus>sent</tns:ncaTrStatus>
<tns:ncaTrReconStatus>n/a</tns:ncaTrReconStatus>
<tns:senderArmReconStatus>n/a</tns:senderArmReconStatus>
</tns:tradeStatusDetails>
<tns:tradeStatusDetails>
<tns:submissionTimestamp>2018-04-10T14:22:22.096000000</tns:submissionTimestamp>
<tns:customerTransactionId>107907</tns:customerTransactionId>
<tns:referenceId>107907</tns:referenceId>
<tns:reportingObligationEntityId>549300GKFG0RYRRQ1414</tns:reportingObligationEntityId>
<tns:tradeDate>2018-04-10</tns:tradeDate>
<tns:reportLevel>T</tns:reportLevel>
<tns:actionType>N</tns:actionType>
<tns:regulation>MiFIR</tns:regulation>
<tns:recordVersion>1</tns:recordVersion>
<tns:userField1>1</tns:userField1>
<tns:lastUpdateTime>22:18:51.760</tns:lastUpdateTime>
<tns:lifecycleStatus>final</tns:lifecycleStatus>
<tns:dataUploadStatus>accepted</tns:dataUploadStatus>
<tns:immediateValidStatus>warning</tns:immediateValidStatus>
<tns:tradeReportMatchStatus>n/a</tns:tradeReportMatchStatus>
<tns:exchangeDataMatchStatus>n/a</tns:exchangeDataMatchStatus>
<tns:assistedReportingMatchStatus>open</tns:assistedReportingMatchStatus>
<tns:postEnrichmentStatus>n/a</tns:postEnrichmentStatus>
<tns:aggregatedValidStatus>warning</tns:aggregatedValidStatus>
<tns:ncaTrStatus>sent</tns:ncaTrStatus>
<tns:ncaTrReconStatus>n/a</tns:ncaTrReconStatus>
<tns:senderArmReconStatus>n/a</tns:senderArmReconStatus>
</tns:tradeStatusDetails>
</tns:tradeStatusReport>
</tns:customerResponse>
在分割中,我必须评估标签的 接受 的文本值是否正确(在此示例中为两种情况):
<tns:ncaTrStatus>accepted</tns:ncaTrStatus>
这些XML将被传递到特定队列......
但是由于标记上的命名空间(tns :)
,无法解析拆分我收到以下错误消息:
2018-04-13 15:48:01:072- [Camel(LRM-Relay)线程#5 - 文件:// mifir /输入/ response4]
[致命错误]:1:25:前缀&#34; tns&#34; for element&#34; tns:tradeStatusDetails&#34;不受约束。
这是我的路线:
Namespaces ns = new Namespaces("tns", "http://deutsche-boerse.com/DBRegHub");
from("{{incoming.path.xmlfile.tradestatus}}")
.routeId("Unmarshal Trade Status (Response 4)")
.autoStartup("{{response.tradestatus.startup}}")
.unmarshal().zipFile()
.split()
.tokenizeXML("tns:tradeStatusDetails")
.streaming()
.log("${body}")
.choice()
.when()
.xpath("//tns:ncaTrStatus/text() = 'accepted'", ns)
.log("Transaction accepted")
.to("{{jms.queue.reply_trades_validations}}")
.otherwise()
.log("${body}")
.to("{{jms.queue.reply_trades_status}}")
.end();
使用Camel版本2.21.0
已解决 - 这是工作片段:
Namespaces ns = new Namespaces("tns", "http://deutsche-boerse.com/DBRegHub");
final XPathBuilder xPathBuilder = XPathBuilder.xpath("//tns:tradeStatusDetails")
.namespaces(ns)
.logNamespaces();
from("{{incoming.path.xmlfile.tradestatus}}")
.routeId("Unmarshal Trade Status (Response 4)")
.autoStartup("{{response.tradestatus.startup}}")
.unmarshal().zipFile()
.split(xPathBuilder)
.parallelProcessing()
.multicast()
.to("direct:toCoreAccepted")
.to("direct:toCoreAcceptedWithWarning")
.to("{{jms.queue.reply_trades_status}}")
.end();
from("direct:toCoreAccepted")
.filter()
.xpath("/tns:tradeStatusDetails[tns:ncaTrStatus = 'accepted']", ns)
.log("Transaction accepted")
.to("{{jms.queue.reply_trades_validations}}")
.end();
from("direct:toCoreAcceptedWithWarnings")
.filter()
.xpath("/tns:tradeStatusDetails[tns:ncaTrStatus = 'accepted with warnings']", ns)
.log("Transaction accepted with warnings")
.to("{{jms.queue.reply_trades_validations}}")
.end();