我使用XMLSpy编写以下XPath来确定最长的字符串长度,并且它可以在XMLSpy中使用:
string-length(//exception:ElementMessageAbcException/@exceptionMsg[not(string-length(.) < //exception:ElementMessageAbcException/@exceptionMsg/string-length(.))] )
但是,当我在春季集成中将相同的字符串放入xpath-expression中时,会出错:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘xpathMaxLengthExceptionMsg’: Instantiation of
bean failed; nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public static
org.springframework.xml.xpath.XPathExpression
org.springframework.xml.xpath.XPathExpressionFactory.createXPathExpression(java.lang.String,java.util.Map)
throws
java.lang.IllegalStateException,org.springframework.xml.xpath.XPathParseException]
threw exception; nested exception is
org.springframework.xml.xpath.XPathParseException: Could not compile
[//exception:MarkitMessageAciException/@exceptionMsg[not(string-length()
<
//exception:MarkitMessageAciException/@exceptionMsg/string-length())]]
to a XPathExpression: null; nested exception is
javax.xml.xpath.XPathExpressionException Caused by: javax.xml.transform.TransformerException: Unknown nodetype: string-length
样本XML:
confirmTs="2014-10-14T11:43:36.191-05:00"
correlationId="ORG-1008891250014" numberAccepted="0"
numberRejected="1" status="exception"
xmlns:ack="http://www.example.net/imdwrd/schemas/Element-message-Abc-ack"
xmlns:confirm="http://www.example.net/imdwrd/schemas/Element-message-Abc-confirm"
xmlns:event="http://www.example.net/imdwrd/schemas/data-source-event"
xmlns:exception="http://www.example.net/imdwrd/schemas/Element-message-Abc-exception"
xmlns:internalClassification="http://www.example.net/imdwrd/schemas/Element-internal-classification"
xmlns:ns9="http://www.example.net/imdwrd/schemas/Element-message-Abc"
xmlns:organization="http://www.example.net/imdwrd/schemas/Element-organization-Abc"
xmlns:pricing="http://www.example.net/imdwrd/schemas/Element-pricing-Abc" xmlns:security="http://www.example.net/imdwrd/schemas/Element-security-Abc">
exceptionMsg="[property]=Organization [message]=Organization information has not changed. Update request has been cancelled."
exceptionType="informational" id="385059141722030" type="organization"/>
exceptionMsg="[property]=Organization [message]=Organizatiosn information has not changed. Update request has been cancelled. longer"
exceptionType="informational" id="385059141722030" type="organization"/>
解决方法:
我不知道XML Spy是如何工作的,但是我看到了这一点:
/@exceptionMsg/string-length(.)
是错误的语法. string-length()实际上是xPath函数,但它不是XML的节点.
目前尚不清楚您的目标是什么,但我希望它能对您有所帮助.
UPDATE
好吧,我已经知道发生了什么事.
因此,您应该使用其他一些库. Saxon是此事上最好的.
但是,您应该这样做:
-Djavax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom=net.sf.saxon.xpath.XPathFactoryImpl
或以编程方式指定该System属性.
标签:spring-integration,java,spring,xml,xpath
来源: https://codeday.me/bug/20191013/1911035.html