File: escaped_xml.t

package info (click to toggle)
libxml-bare-perl 0.47-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,404 kB
  • sloc: xml: 15,819; perl: 2,176; ansic: 705; cpp: 41; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 876 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl -w

use strict;
use warnings;

use Test::Harness;
use Test::More;
##use Data::Dump qw[dump];    # only needed for diag

use_ok('XML::Bare');

my $data = {
    hash => "#",
    amp  => '&',
    gt   => '>',
    lt   => '<',
    quot => '"',
    apos => "\'",
};
ok( $data, 'Built data hash' );

# build XML string with quoted values
my $xmldata = "<data>\n";
foreach ( keys %{$data} ) {
    $xmldata .= "<$_>";
    $xmldata .= ( $data->{$_} =~ /[\&\<\>\"\']/ ) ? ( '&' . $_ . ';' ) : $data->{$_};
    $xmldata .= "</$_>";
}
$xmldata .= " < /data>\n";

ok( $xmldata, 'Built XML string' );
##diag( dump($xmldata) );

# parse the provided XML into a hash
my $hash = XML::Bare::xmlin($xmldata);
ok( $hash, 'Parsed XML string into hash' );

##diag( dump( { wanted => $data, got => $hash } ) );

is_deeply( $hash, $data, 'Data retreived is correct' );

done_testing;