3

I have xml message body as below. I need to find out if string length of the attribute 'SenderId' is greater than 0. I am unable to find this.

XML Message

<?xml version="1.0"?>
<Audit xmlns="http://schemas.Auditlog.xsd">
<MessageId>1234</MessageId>
<SenderDetails CreatedDate="2017-Jan-12" SenderId="App1"/>
</Audit>

I am using below xpath function to get the string length of SenderId

when(xpath("string-length(string(//node()[local-name()='SenderDetails']/@[local-name()='SenderId']/text()))>0))

But it is not working.

halfer
  • 19,824
  • 17
  • 99
  • 186
Deeps
  • 45
  • 1
  • 4

1 Answers1

2

This XPath,

string-length(//*[local-name() = 'SenderDetails']/@SenderId)

will return 4 because the attribute value of @SenderId is App1, which has a string length of 4. You can test its return value by appending > 0 if you wish to return true for positive numbers.

See How does XPath deal with XML namespaces? to learn how to declare and use a namespace prefix in your XPath, which is preferable to defeating namespaces via local-name().

kjhughes
  • 106,133
  • 27
  • 181
  • 240