1

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>

and I am stuck with it.

I am trying to evaluate the value of the EventType node. I have tried:

/ExternalEvent/EventType

and

/*[local-name() = 'ExternalPath' and *[local-name() = 'EventType']]

and

/*[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']

plus many other variations. However in XPath Tester I always get the same error which is:

The default (no prefix) Namespace URI for XPath queries is always '' and it cannot be redefined to 'http://www.redeyedmonster.co.uk/Integration/ESB'.

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.

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.

Nigel B
  • 3,577
  • 3
  • 34
  • 52
  • Your last option should work fine, but the usual way to deal with namespaces in XPath is to bind the URI to a prefix and then use that prefix in the expressions (e.g. `/esb:ExternalEvent/esb:EventType`). Exactly how you declare prefix bindings varies between different XPath engines - what tool or library are you using to execute these XPath expressions? – Ian Roberts Aug 30 '13 at 10:35
  • That error message appears to be a limitation of the tester you're using rather than a problem with the expression you're trying to test. – Ian Roberts Aug 30 '13 at 10:38
  • I am actually trying to resolve this within a BizTalk ESB Messaging Broker Extender that doesn't appear to want to play :( – Nigel B Aug 30 '13 at 10:51

1 Answers1

1

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.

Rahul
  • 170
  • 2
  • 14