📄 parser.html
字号:
a relative name, then it is relative to the current working directory.</p>
<p>
</p>
<h2><a name="externentfin__expat_">ExternEntFin (Expat)</a></h2>
<p>This is called after parsing an external entity. It's not called unless
an ExternEnt handler is also set. There is a default handler installed
that pairs with the default ExternEnt handler.</p>
<p>If you're going to install your own ExternEnt handler, then you should
set (or unset) this handler too.</p>
<p>
</p>
<h2><a name="entity__expat__name__val__sysid__pubid__ndata__isparam_">Entity (Expat, Name, Val, Sysid, Pubid, Ndata, IsParam)</a></h2>
<p>This is called when an entity is declared. For internal entities, the Val
parameter will contain the value and the remaining three parameters will be
undefined. For external entities, the Val parameter will be undefined, the
Sysid parameter will have the system id, the Pubid parameter will have the
public id if it was provided (it will be undefined otherwise), the Ndata
parameter will contain the notation for unparsed entities. If this is a
parameter entity declaration, then the IsParam parameter is true.</p>
<p>Note that this handler and the Unparsed handler above overlap. If both are
set, then this handler will not be called for unparsed entities.</p>
<p>
</p>
<h2><a name="element__expat__name__model_">Element (Expat, Name, Model)</a></h2>
<p>The element handler is called when an element declaration is found. Name
is the element name, and Model is the content model as an XML::Parser::Content
object. See <a href="../../lib/XML/Parser/Expat.html#xml__parser__contentmodel_methods">XML::Parser::ContentModel Methods in the XML::Parser::Expat manpage</a>
for methods available for this class.</p>
<p>
</p>
<h2><a name="attlist__expat__elname__attname__type__default__fixed_">Attlist (Expat, Elname, Attname, Type, Default, Fixed)</a></h2>
<p>This handler is called for each attribute in an ATTLIST declaration.
So an ATTLIST declaration that has multiple attributes will generate multiple
calls to this handler. The Elname parameter is the name of the element with
which the attribute is being associated. The Attname parameter is the name
of the attribute. Type is the attribute type, given as a string. Default is
the default value, which will either be "#REQUIRED", "#IMPLIED" or a quoted
string (i.e. the returned string will begin and end with a quote character).
If Fixed is true, then this is a fixed attribute.</p>
<p>
</p>
<h2><a name="doctype__expat__name__sysid__pubid__internal_">Doctype (Expat, Name, Sysid, Pubid, Internal)</a></h2>
<p>This handler is called for DOCTYPE declarations. Name is the document type
name. Sysid is the system id of the document type, if it was provided,
otherwise it's undefined. Pubid is the public id of the document type,
which will be undefined if no public id was given. Internal is the internal
subset, given as a string. If there was no internal subset, it will be
undefined. Internal will contain all whitespace, comments, processing
instructions, and declarations seen in the internal subset. The declarations
will be there whether or not they have been processed by another handler
(except for unparsed entities processed by the Unparsed handler). However,
comments and processing instructions will not appear if they've been processed
by their respective handlers.</p>
<p>
</p>
<h2><a name="__doctypefin__parser_">* DoctypeFin (Parser)</a></h2>
<p>This handler is called after parsing of the DOCTYPE declaration has finished,
including any internal or external DTD declarations.</p>
<p>
</p>
<h2><a name="xmldecl__expat__version__encoding__standalone_">XMLDecl (Expat, Version, Encoding, Standalone)</a></h2>
<p>This handler is called for xml declarations. Version is a string containg
the version. Encoding is either undefined or contains an encoding string.
Standalone will be either true, false, or undefined if the standalone attribute
is yes, no, or not made respectively.</p>
<p>
</p>
<hr />
<h1><a name="styles">STYLES</a></h1>
<p>
</p>
<h2><a name="debug">Debug</a></h2>
<p>This just prints out the document in outline form. Nothing special is
returned by parse.</p>
<p>
</p>
<h2><a name="subs">Subs</a></h2>
<p>Each time an element starts, a sub by that name in the package specified
by the Pkg option is called with the same parameters that the Start
handler gets called with.</p>
<p>Each time an element ends, a sub with that name appended with an underscore
("_"), is called with the same parameters that the End handler gets called
with.</p>
<p>Nothing special is returned by parse.</p>
<p>
</p>
<h2><a name="tree">Tree</a></h2>
<p>Parse will return a parse tree for the document. Each node in the tree
takes the form of a tag, content pair. Text nodes are represented with
a pseudo-tag of "0" and the string that is their content. For elements,
the content is an array reference. The first item in the array is a
(possibly empty) hash reference containing attributes. The remainder of
the array is a sequence of tag-content pairs representing the content
of the element.</p>
<p>So for example the result of parsing:</p>
<pre>
<foo><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo></pre>
<p>would be:</p>
<pre>
<span class="variable">Tag</span> <span class="variable">Content</span>
<span class="operator">==================================================================</span>
<span class="operator">[</span><span class="variable">foo</span><span class="operator">,</span> <span class="operator">[{}</span><span class="operator">,</span> <span class="variable">head</span><span class="operator">,</span> <span class="operator">[{</span><span class="string">id</span> <span class="operator">=></span> <span class="string">"a"</span><span class="operator">}</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="string">"Hello "</span><span class="operator">,</span> <span class="variable">em</span><span class="operator">,</span> <span class="operator">[{}</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="string">"there"</span><span class="operator">]]</span><span class="operator">,</span>
<span class="variable">bar</span><span class="operator">,</span> <span class="operator">[</span> <span class="operator">{}</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="string">"Howdy"</span><span class="operator">,</span> <span class="keyword">ref</span><span class="operator">,</span> <span class="operator">[{}]]</span><span class="operator">,</span>
<span class="number">0</span><span class="operator">,</span> <span class="string">"do"</span>
<span class="operator">]</span>
<span class="operator">]</span>
</pre>
<p>The root document "foo", has 3 children: a "head" element, a "bar"
element and the text "do". After the empty attribute hash, these are
represented in it's contents by 3 tag-content pairs.</p>
<p>
</p>
<h2><a name="objects">Objects</a></h2>
<p>This is similar to the Tree style, except that a hash object is created for
each element. The corresponding object will be in the class whose name
is created by appending "::" and the element name to the package set with
the Pkg option. Non-markup text will be in the ::Characters class. The
contents of the corresponding object will be in an anonymous array that
is the value of the Kids property for that object.</p>
<p>
</p>
<h2><a name="stream">Stream</a></h2>
<p>This style also uses the Pkg package. If none of the subs that this
style looks for is there, then the effect of parsing with this style is
to print a canonical copy of the document without comments or declarations.
All the subs receive as their 1st parameter the Expat instance for the
document they're parsing.</p>
<p>It looks for the following routines:</p>
<ul>
<li><strong><a name="item_startdocument">StartDocument</a></strong>
<p>Called at the start of the parse .</p>
</li>
<li><strong><a name="item_starttag">StartTag</a></strong>
<p>Called for every start tag with a second parameter of the element type. The $_
variable will contain a copy of the tag and the %_ variable will contain
attribute values supplied for that element.</p>
</li>
<li><strong><a name="item_endtag">EndTag</a></strong>
<p>Called for every end tag with a second parameter of the element type. The $_
variable will contain a copy of the end tag.</p>
</li>
<li><strong><a name="item_text">Text</a></strong>
<p>Called just before start or end tags with accumulated non-markup text in
the $_ variable.</p>
</li>
<li><strong><a name="item_pi">PI</a></strong>
<p>Called for processing instructions. The $_ variable will contain a copy of
the PI and the target and data are sent as 2nd and 3rd parameters
respectively.</p>
</li>
<li><strong><a name="item_enddocument">EndDocument</a></strong>
<p>Called at conclusion of the parse.</p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="encodings">ENCODINGS</a></h1>
<p>XML documents may be encoded in character sets other than Unicode as
long as they may be mapped into the Unicode character set. Expat has
further restrictions on encodings. Read the xmlparse.h header file in
the expat distribution to see details on these restrictions.</p>
<p>Expat has built-in encodings for: <code>UTF-8</code>, <code>ISO-8859-1</code>, <code>UTF-16</code>, and
<code>US-ASCII</code>. Encodings are set either through the XML declaration
encoding attribute or through the ProtocolEncoding option to XML::Parser
or XML::Parser::Expat.</p>
<p>For encodings other than the built-ins, expat calls the function
load_encoding in the Expat package with the encoding name. This function
looks for a file in the path list @XML::Parser::Expat::Encoding_Path, that
matches the lower-cased name with a '.enc' extension. The first one it
finds, it loads.</p>
<p>If you wish to build your own encoding maps, check out the XML::Encoding
module from CPAN.</p>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>Larry Wall <<em><a href="mailto:larry@wall.org">larry@wall.org</a></em>> wrote version 1.0.</p>
<p>Clark Cooper <<em><a href="mailto:coopercc@netheaven.com">coopercc@netheaven.com</a></em>> picked up support, changed the API
for this version (2.x), provided documentation,
and added some standard package features.</p>
<p>Matt Sergeant <<em><a href="mailto:matt@sergeant.org">matt@sergeant.org</a></em>> is now maintaining XML::Parser</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -