undefined function 'xmls:getString'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


undefined function 'xmls:getString'



I am trying to run a small program with ballerina. Here's my code.




import ballerina.lang.system;
import ballerina.lang.xmls;
function main(string args) {
system:println("Hello, World!");
string xmlvar = "<bookstore>n<book category="cooking">n <title lang="en">Everyday Italian</title>n <author>Giada De Laurentiis</author>n <year>2005</year>n <price>30.00</price>n</book>n<bookstore>";
string var1 = xmls:getString(xmlvar, "/bookstore/book[1]");
system:println(var1);

}



I have already imported ballerina.lang.xmls.



Any idea ?





You are trying to pass a ballerina string value to the getString method signature hence the error. getString(xml msg, string xPath)
– Suhan Dharmasuriya
Feb 22 '17 at 7:29




getString(xml msg, string xPath)




1 Answer
1



Please try the following.


import ballerina.lang.system;
import ballerina.lang.xmls;

function main(string args) {

xml payload = `<bookstore><book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price></book></bookstore>`;

system:println(xmls:getString(payload, "/bookstore/book[1]"));
}



Also correct your end tag to </bookstore>


</bookstore>



Please refer documentation for more information.
http://ballerinalang.org/docs/api/0.8/ballerina.lang.xmls.html#getString





Thanks, got it to working.
– Tharindu Edirisinghe
Feb 22 '17 at 7:48






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived