Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml Xpath函数查找属性的字符串长度_Xml_Xpath - Fatal编程技术网

Xml Xpath函数查找属性的字符串长度

Xml Xpath函数查找属性的字符串长度,xml,xpath,Xml,Xpath,我有如下xml消息体。我需要找出属性“SenderId”的字符串长度是否大于0。我找不到这个 XML消息 <?xml version="1.0"?> <Audit xmlns="http://schemas.Auditlog.xsd"> <MessageId>1234</MessageId> <SenderDetails CreatedDate="2017-Jan-12" SenderId="App1"/> </Audit>

我有如下xml消息体。我需要找出属性“SenderId”的字符串长度是否大于0。我找不到这个

XML消息

<?xml version="1.0"?>
<Audit xmlns="http://schemas.Auditlog.xsd">
<MessageId>1234</MessageId>
<SenderDetails CreatedDate="2017-Jan-12" SenderId="App1"/>
</Audit>
但它不起作用。

这个XPath

string-length(//*[local-name() = 'SenderDetails']/@SenderId)
将返回4,因为
@SenderId
的属性值是
App1
,其字符串长度为4。如果希望为正数返回true,可以通过追加
>0来测试其返回值


请参见了解如何在XPath中声明和使用名称空间前缀,这比通过
local-name()

击败名称空间更可取。执行XPath时使用的环境是什么,即宿主编程语言/DOM API是什么?它是基于spring的项目,使用Java DSL编程
string-length(//*[local-name() = 'SenderDetails']/@SenderId)