Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

Read XML Tag value

Hai All,
I have an xml file which contain data like

test.xml
<Book>
<ID>1</ID>
<NAME>ABCD</NAME>
<PRICE>12.23</PRICE>
</Book>

and I need to get the text which is between 'NAME' tag. Please answer ASAP.
_log("Name"+$name);

the $name should get the text 'ABCD'
Eg: Name = ABCD

Answers

  • Hai,
    This is the answer I found and its working fine... the code is below...

    var $XMLStr = _readFile("test.xml");
    _set($XMLStr,$XMLStr.toString());
    $XMLStr = $XMLStr.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "");
    var $x = new XML($XMLStr);
    var $value=$x.Book[0].NAME.toString();
    _log($value);
Sign In or Register to comment.