in reply to LibXML 'Fun'

Now, the obvious question is, what am i doing wrong?

Is that a literal copy/paste of your code? If so, proper (or at least consistent) indentation might help sort things out, or at least would help to rule out potential culprits. Looking at your code, my first impression was a scoping issue, along the lines of

while ( my $row = ... ) { my $node = ... } $list[0]->push($node); # node may be undef
Indentation would have made this one easier to rule out. My second impression is that $list[0] isn't really where you want to put your new tree, but then you're not showing us code that prints the page, so I can't tell.

Please consider a small, complete example that demonstrates the problem. The process of producing such an example is often sufficient to flush out the culprit.

Replies are listed 'Best First'.
Re: Re: LibXML 'Fun'
by stefzody (Acolyte) on Oct 12, 2003 at 00:43 UTC
    Hey there, Thanks for the thought, i dont think it is scoping but, in the interest of 'full disclosure' here the code. its a Handler for Apache/mod_perl, however i dont think that this is a problem with that, more LibXML. Anyway, here is the code:
    sub start { my ($r,$params) = @_; # open the database handle and get the data from the table my $db=LMS2::Library->open_lms(); my $cat_sth = $db->prepare("SELECT * FROM CompCat ORDER BY descrip +tion "); $cat_sth->execute; my $parser = XML::LibXML->new(); my $XMLPath = $r->server_root_relative("LMS2/XML"); my $location = $r->location(); my $tree=$parser->parse_file($XMLPath."/Competancy.xml"); my $first; # prepare list of categories my @list2 = $tree->findnodes('//select[@id="categoryID"]') || warn "couldnt find any nodes for select & name of cate +goryID"; while (my $row=$cat_sth->fetchrow_hashref ) { my $node = XML::LibXML::Element->new('option'); $node->setAttribute('value',$row->{id}); if ($row->{id} == $params->{categoryID}) { $node->setAttribute('selected','selected'); } my $text = XML::LibXML::Text->new($row->{description}); $node->appendChild($text); $list2[0]->push($node); } my $parser2 = XML::LibXSLT->new(); my $ss=$parser2->parse_stylesheet_file($XMLPath."/HTMLConvert.xsl" +); my $res=$ss->transform($tree); my $htmlpage = $ss->output_string($res); $htmlpage =~ s/__HOST__/$hn{Host}/gim; $r->print($htmlpage); }
      I'm ignorant of this aspect of LibXML, but are you sure that
      $list2[0]->push($node);
      side-effects $tree?

      Should I assume that you're printing a content-header in code that you haven't shown? Or is the content header part of the XSL?

        ah. now, thats a thought. i was assuming that it did indeed change the xml file loaded into $tree. I will go and play around with that, thank you for the pointer and thought :)

        Also, a small note, i have the header in the XML file as is. i take it that this is 'frowned upon' ?