[Koha-bugs] [Bug 7170] Remove use of XML::Simple

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Jul 8 04:37:13 CEST 2016


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=7170

M. Tompsett <mtompset at hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mtompset at hotmail.com

--- Comment #19 from M. Tompsett <mtompset at hotmail.com> ---
I was looking in the svc ones and came up with this hackiness.

sub build_xml_output {
    my ($xml_hash, $root_name) = @_;

    my @xml_tags = keys %{$xml_hash};
    my @values = map { { 'key' => $_, 'value' => $xml_hash->{$_} } } @xml_tags;
    my $xml_values;
    foreach my $value (@values) {
        $xml_values->{$value->{key}} = $value->{value};
    }

    my $dom = XML::LibXML::Document->new( '1.0', q{} );
    $dom->setStandalone(1);
    my $root = $dom->createElement( $root_name );
    $dom->setDocumentElement( $root );
    foreach my $xml_tag (@xml_tags) {
        my $xml_value = $xml_values->{$xml_tag};

        my $text = $dom->createTextNode( "\n  " );
        $root->appendChild($text);

        my $element = $dom->createElement( $xml_tag );
        $root->appendChild($element);

        if ($xml_value =~ /\<datafield/ ) {
            my $parser = XML::LibXML->new();
            my $fragment = $parser->parse_balanced_chunk( $xml_value );
            $element->appendChild( $fragment );
        }
        else {
            $text = $dom->createTextNode( $xml_value );
            $element->appendTextNode($text);
        }
    }

    my $text = $dom->createTextNode( "\n" );
    $root->appendChild($text);

    my $xml_output = $dom->toString(0);
    print $xml_output;
}

You can see why XML::Simple with its XMLout method is desirable. :)

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list