in reply to Re: LibXML 'Fun'
in thread LibXML 'Fun'

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); }

Replies are listed 'Best First'.
Re: Re: Re: LibXML 'Fun'
by dws (Chancellor) on Oct 12, 2003 at 01:07 UTC
    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' ?

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

        Not at all. The lack of a content-type header is a likely culprit for the symptoms you reported, so I asked. Putting the content-type header (and any other necessary headers) in the template gives a more cohesive solution than putting the content-type into code and the content into a separate template. On the other hand, emitting a content-header early, from code, makes a number of problems easier to diagnose.