Hello there, recently i got asked to branch into XML and all the assorted joys that go along with it (xslt, xpath, etc)

Anyway, I have a parser running and my XML, and i am trying to put options into a select box, using values that I have in a database. I can get the data out and finding the correct select to 'replace' or update with the options.

I have managed to get some code that looks roughly as follows:

my @list = $tree->findnodes('//select[@id="categoryID"]') || warn "cou +ldnt find any nodes for select & name of categoryID"; 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); $list[0]->push($node);

Now, the obvious question is, what am i doing wrong ? When the page is printed out, none of the other values that i put in present. (Yes, i have also made sure that the values are retrieved from the database, i think this is more a 'misunderstanding' of NodeLists, XML::LibXML and how to add new nodes into it)

thanks


In reply to LibXML 'Fun' by stefzody

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.