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 2008-06-18 20:53:49-07 by guttersnipe in response to 7908
Re: getting setData to work
Cindy,

I was having this same issue when I was also trying to run the setData() method against the XML::LibXML::Element object. As you can see from the XML::LibXML::Element and XML::LibXML::Text documentation, the setData() method only exists in the latter.

There is, however, a wrapper method for the Element class called appendTextNode( $string ) that appends the argument $string to the end of the existing text for that element. Why there is no replaceTextNode() method escapes me. But, in the meantime, it seems that in order to replace instead of append, you need to be working with a Text object--not a Element object. This is accomplished by amending your xpath expression.

my @nodes=$doc->findnodes("//*[@lang='greek']");

After the above line executes, each element of the @nodes array will consist of an XML::LibXML::Element object. You want each of these elements to consist of an XML::LibXML::Text object. Change the line to:

my @nodes=$doc->findnodes("//*[@lang='greek']/text()");

...and wala! You can now iterate through the array of XML::LibXML::Text objects and--therefore--preform the setText() method on those objects.

Cheers!
Direct Responses: 8102 | Write a response