XML package addAttributes: attribute name from variable

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

XML package addAttributes: attribute name from variable

xiaolong
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: XML package addAttributes: attribute name from variable

xiaolong
This post has NOT been accepted by the mailing list yet.
I don't know why my post does not get accepted by the mailing list.

xiaolong wrote
According to the help, this is how I add attribute:

> library(XML)
> b = newXMLNode("test node", "text")
> addAttributes(b, a = 1)
<test node a="1">text</test node> 

In this syntax, the attribute name (“a” in this case) is hard-coded.

What if the attribute name needs to come from a variable? For example:

> atr_name = "test_atr";
> addAttributes(b, atr_name = 1)
<test node a="1" atr_name="1">text</test node> 

As you can see, I did not get what I wanted. The name is “atr_name”, not “test_atr”.
 
Thanks!