XPath 错误 - XPath 查询的默认(无前缀)命名空间 URI 始终为“" [英] XPath Error - The default (no prefix) Namespace URI for XPath queries is always ''
问题描述
我有这个示例格式的 XML:
I have XML in this example format:
<ExternalEvent xmlns="http://www.redeyedmonster.co.uk/Integration/ESB">
<EventType>Create</EventType>
<Message>SomeMessage</Message>
<ServiceRequestId>75a144b8-5a11-e311-bd23-0050569f00cc</ServiceRequestId>
<SourceSystem>MySource</SourceSystem>
</ExternalEvent>
我被它困住了.
我正在尝试评估 EventType 节点的值.我试过了:
I am trying to evaluate the value of the EventType node. I have tried:
/ExternalEvent/EventType
和
/*[local-name() = 'ExternalPath' and *[local-name() = 'EventType']]
和
/*[local-name()='ExternalEvent' and namespace-uri()='http://www.redeyedmonster.co.uk/Integration/ESB']/*[local-name()='EventType' and namespace-uri()='http://www.redeyedmonster.co.uk/Integration/ESB']
加上许多其他变体.但是在 XPath Tester 中,我总是遇到相同的错误:
plus many other variations. However in XPath Tester I always get the same error which is:
XPath 查询的默认(无前缀)命名空间 URI 始终为 '',并且不能重新定义为 'http://www.redeyedmonster.co.uk/Integration/ESB'.
The default (no prefix) Namespace URI for XPath queries is always '' and it cannot be redefined to 'http://www.redeyedmonster.co.uk/Integration/ESB'.
如果我从 XML 中删除命名空间短语 (xmlns="http://www.redeyedmonster.co.uk/Integration/ESB") 那么我就可以评估事件类型的值没问题但不幸的是我坚持使用这种格式的 XML,我的解决方案无法更改它.
If I remove the namespace phrase (xmlns="http://www.redeyedmonster.co.uk/Integration/ESB") from the XML then I am able to evaluate the value of event type no problem but unfortunately I am stuck with XML in this format and it cannot be changed for my solution.
有没有办法解决这个问题?我相信这可能是我在 ESB 解决方案中遇到路由问题的根本原因.
Is there a way round this? As I believe it may be the the underlying cause of a routing problem I have in my ESB solution.
推荐答案
有没有试过用表达式直接获取EventType
数据像[//*local-name()='EventType']
或者你甚至可以尝试类似 [/*localname()='ExternalPath'/*local-name()='EventType']
don't 使用和.
Have you tried to get the node by using the expression to directly get EventType
data like [//*local-name()='EventType']
or you can even try something like [/*localname()='ExternalPath'/*local-name()='EventType']
don't use and.
这篇关于XPath 错误 - XPath 查询的默认(无前缀)命名空间 URI 始终为“"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!