Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get length of String

Tags:

xpath

Dear Users,

 <note>
    <to>ToText</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
 </note>

I am in need to get the string length of XML tag using Xpath. I am using string-lenth(), but not able to render exact result.

Is there a way to get string-lenght(/to) or string-lenght(/from)?

like image 452
Sriram Rammohan Avatar asked Feb 08 '17 08:02

Sriram Rammohan


People also ask

How do you find the length of a string?

As you know, the best way to find the length of a string is by using the strlen() function.

What is the length of the string?

The length or size of a string means the total number of characters present in it. For Example: The string “Geeks For Geeks” has 15 characters (including spaces also).

How do you get the length of a string in Java?

Java String length method() The Java String class contains a length() method that returns the total number of characters a given String contains. This value includes all blanks, spaces, and other special characters. Every character in the String is counted.

What is length () in Java?

The length() method returns the length of a specified string. Note: The length of an empty string is 0.


2 Answers

Try to use below XPath:

//from/string-length(text())

or

//to/string-length(text())
like image 166
Andersson Avatar answered Sep 29 '22 11:09

Andersson


Mathias Muller is correct, this should work: string-length(/note/to) or string-length(/note/from)

please check your spelling of length as well.....

like image 24
becixb Avatar answered Sep 29 '22 13:09

becixb