获取字符串长度

Sri*_*han 5 xpath

尊敬的用户,

 <note>
    <to>ToText</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
 </note>
Run Code Online (Sandbox Code Playgroud)

我需要XML使用Xpath. 我正在使用string-lenth(),但无法呈现准确的结果。

有没有办法得到string-lenght(/to)string-lenght(/from)

And*_*son 5

尝试在下面使用XPath

//from/string-length(text())
Run Code Online (Sandbox Code Playgroud)

或者

//to/string-length(text())
Run Code Online (Sandbox Code Playgroud)

  • 如果文档结构已知,则应避免使用 `//`。您的建议仅适用于 XPath 2.0。例如,在 XPath 1.0 中,函数不能是轴步,表达式必须是 `string-length(/note/to)`。 (2认同)