655
|
1 |
=head1 NAME
|
|
2 |
|
|
3 |
XML::DOM::Parser - An XML::Parser that builds XML::DOM document structures
|
|
4 |
|
|
5 |
=head1 SYNOPSIS
|
|
6 |
|
|
7 |
use XML::DOM;
|
|
8 |
|
|
9 |
my $parser = new XML::DOM::Parser;
|
|
10 |
my $doc = $parser->parsefile ("file.xml");
|
|
11 |
|
|
12 |
=head1 DESCRIPTION
|
|
13 |
|
|
14 |
XML::DOM::Parser extends L<XML::Parser>
|
|
15 |
|
|
16 |
The XML::Parser module was written by Clark Cooper and
|
|
17 |
is built on top of XML::Parser::Expat,
|
|
18 |
which is a lower level interface to James Clark's expat library.
|
|
19 |
|
|
20 |
XML::DOM::Parser parses XML strings or files
|
|
21 |
and builds a data structure that conforms to the API of the Document Object
|
|
22 |
Model as described at L<http://www.w3.org/TR/REC-DOM-Level-1>.
|
|
23 |
See the L<XML::Parser> manpage for other additional properties of the
|
|
24 |
XML::DOM::Parser class.
|
|
25 |
Note that the 'Style' property should not be used (it is set internally.)
|
|
26 |
|
|
27 |
The XML::Parser B<NoExpand> option is more or less supported, in that it will
|
|
28 |
generate EntityReference objects whenever an entity reference is encountered
|
|
29 |
in character data. I'm not sure how useful this is. Any comments are welcome.
|
|
30 |
|
|
31 |
As described in the synopsis, when you create an XML::DOM::Parser object,
|
|
32 |
the parse and parsefile methods create an L<XML::DOM::Document> object
|
|
33 |
from the specified input. This Document object can then be examined, modified and
|
|
34 |
written back out to a file or converted to a string.
|
|
35 |
|
|
36 |
When using XML::DOM with XML::Parser version 2.19 and up, setting the
|
|
37 |
XML::DOM::Parser option B<KeepCDATA> to 1 will store CDATASections in
|
|
38 |
CDATASection nodes, instead of converting them to Text nodes.
|
|
39 |
Subsequent CDATASection nodes will be merged into one. Let me know if this
|
|
40 |
is a problem.
|
|
41 |
|
|
42 |
=head1 Using LWP to parse URLs
|
|
43 |
|
|
44 |
The parsefile() method now also supports URLs, e.g. I<http://www.erols.com/enno/xsa.xml>.
|
|
45 |
It uses LWP to download the file and then calls parse() on the resulting string.
|
|
46 |
By default it will use a L<LWP::UserAgent> that is created as follows:
|
|
47 |
|
|
48 |
use LWP::UserAgent;
|
|
49 |
$LWP_USER_AGENT = LWP::UserAgent->new;
|
|
50 |
$LWP_USER_AGENT->env_proxy;
|
|
51 |
|
|
52 |
Note that env_proxy reads proxy settings from environment variables, which is what I need to
|
|
53 |
do to get thru our firewall. If you want to use a different LWP::UserAgent, you can either set
|
|
54 |
it globally with:
|
|
55 |
|
|
56 |
XML::DOM::Parser::set_LWP_UserAgent ($my_agent);
|
|
57 |
|
|
58 |
or, you can specify it for a specific XML::DOM::Parser by passing it to the constructor:
|
|
59 |
|
|
60 |
my $parser = new XML::DOM::Parser (LWP_UserAgent => $my_agent);
|
|
61 |
|
|
62 |
Currently, LWP is used when the filename (passed to parsefile) starts with one of
|
|
63 |
the following URL schemes: http, https, ftp, wais, gopher, or file (followed by a colon.)
|
|
64 |
If I missed one, please let me know.
|
|
65 |
|
|
66 |
The LWP modules are part of libwww-perl which is available at CPAN.
|