You want to paste the element at the end of the proper classes element.
It can be a bit of a pain to write because of the interaction between the quotes in Perl and in XPath (and the fact that @ means something different in both languages), so here is a way to do it:
Just in case you don't know this: qq{...} is an alternate way of writing "...", and the @ needs to be backslashed or Perl sees it as an array to be interpolated in the string.
A couple of comments: classes seems weird as an element name, as it looks like it contains only 1 class, so why the plural? Instead of $className = $element->{'att'}-*gt;{"name"}; you should really write $className = $element->att( "name"); . This is the "official" way to access attributes, and even though what you wrote works today there is nothing in the published API for XML::Twig that garantees that it will work in the future (ie I could possibly change the implementation of attributes).
Does this help?
Hi,
Did you try using the code I gave you? If you replace the "??? where to paste this" line in your original code with the 3 lines I gave you, it will insert the new User element in the Classes element with a name attribute of Nursery (as the last element in the parent).
Isn't that what you are trying to do?
--
mirod
Just in case anyone was interested, the first task would using XML::Rules look like this:
and the other, using a over the weekend to be released version, would look like this