I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2006-09-01 14:44:01-07 by mirod in response to 2885
Re: reading and writing into xml

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:

my $class_name= "Nursery"; my $class= $root->first_child( qq{classes[\@name="$class_name"]}); $node->paste( last_child => $class);

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?

Direct Responses: 2913 | 2914 | Write a response