- or download this
<library>
<book>
...
width="100" height="125" />
</book>
</library>
- or download this
#!/usr/bin/perl
...
use warnings;
my $filename = 'library.xml';
- or download this
use XML::Simple qw(:strict);
...
foreach my $book (@{$library->{book}}) {
print $book->{title}->[0], "\n"
}
- or download this
use XML::LibXML;
...
my($title) = $book->findnodes('./title');
print $title->to_literal, "\n"
}
- or download this
foreach my $title ($doc->findnodes('/library/book/title')) {
print $title->to_literal, "\n"
}
- or download this
print $_->data . "\n" foreach ($doc->findnodes('//book/title/text()'
+));
- or download this
use XML::Simple qw(:strict);
...
my $book = $library->{book}->{$isbn};
print "$_\n" foreach(@{$book->{author}});
- or download this
use XML::LibXML;
...
my $query = "//book[isbn/text() = '$isbn']/author/text()";
print $_->data . "\n" foreach ($doc->findnodes($query));
- or download this
my $library = XMLin($filename, ForceArray => [ 'book' ], KeyAttr =>
+ {});
foreach my $book (@{$library->{book}}) {
print $book->{isbn}, "\n" if $book->{pages} > 900;
}
- or download this
use XML::Simple qw(:strict);
...
$book->{pages}->[0] = '394';
print $xs->XMLout($ref);
- or download this
use XML::LibXML;
...
$node->setData('394');
print $doc->toString;
- or download this
my($book) = $doc->findnodes("//book[isbn = '$isbn']");
my $library = $book->parentNode;
$library->removeChild($book);
- or download this
my $rating = $doc->createElement('rating');
$rating->appendTextNode('5');
$book->appendChild($rating);
- or download this
$book->appendTextChild('rating', '5');
- or download this
my $fragment = $parser->parse_balanced_chunk(
'<rating>5</rating><price>32.00</price>'
);
$book->appendChild($fragment);
- or download this
xmllint --format -