Regarding XML Library

219 views
Skip to first unread message

Ganesh Kumbhar

unread,
Oct 1, 2014, 2:09:45 AM10/1/14
to robotframe...@googlegroups.com
Hi ,

I have to update the element text in an xml file .
I tried using Set Element Text bt its not working as expected .
 and i didnt get use of tail 
can you give an example for using that function ?

"Set Element Text  common.xml  ${Para_Set_Element_text}  xpath=.//parameterversion" this is my statement
parameterversion  is element i.e. tag name
Para_Set_Element_text  is var i need to put there

kindly provide some solution

Thank U.


Best Regards,
Ganesh Kumbhar

Pekka Klärck

unread,
Oct 2, 2014, 5:50:04 PM10/2/14
to gbkum...@gmail.com, robotframework-users
2014-10-01 9:09 GMT+03:00 Ganesh Kumbhar <gbkum...@gmail.com>:
>
> I have to update the element text in an xml file .
> I tried using Set Element Text bt its not working as expected .
> and i didnt get use of tail
> can you give an example for using that function ?

Could you first give an example what you actually tried and explain
why it didn't work as you expected? This keyword has acceptance tests
that pass so I doubt it is totally broken.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Pekka Klärck

unread,
Oct 4, 2014, 6:09:42 PM10/4/14
to Ganesh Kumbhar, robotframework-users
[Added robotframework-users back to Cc.]

2014-10-04 9:08 GMT+03:00 Ganesh Kumbhar <gbkum...@gmail.com>:
> Hi
> I have xml file common.xml.and one in tag <RollNo>39</RollNo>
> so I have to get that text i.e. 39 and update that text to some other value
> or just increment by 1.
> I successfully able to get text but unabe to update that.
> I used function Set Element Text as
> Set Element Text common.xml ${incremented value} xpath=.//RollNo
> This function get passed successfully but that value cant get updated

The reason the above doesn't work is that Set Element Text doesn't
modify the original XML file. It returns you the modified XML
structure, though, and you can then use Save XML to save it:

${xml} = Set Element Text common.xml ${incremented value}
xpath=.//RollNo
Save XML ${xml} common.xml

Notice that if you would give Set Element Text an already parsed XML
strucutre, it would modify it in place in addition to returning it. In
other words, this would also work:

${xml} = Parse XML common.xml
Set Element Text ${xml} ${incremented value} xpath=.//RollNo
Save XML ${xml} common.xml

This is by design but it clearly not too well documented. Hopefully
docs are a bit more clear after this commit:
https://github.com/robotframework/robotframework/commit/9d8c470d4431ad2ef8b52bf2a6f867e05ba0817d
Reply all
Reply to author
Forward
0 new messages