📄 expat.html
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../../displayToc.js"></script>
<script language="JavaScript" src="../../../tocParas.js"></script>
<script language="JavaScript" src="../../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../../scineplex.css">
<title>XML::Parser::Expat - Lowlevel access to James Clark's expat XML parser</title>
<link rel="stylesheet" href="../../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',3);</script>
<h1><a>XML::Parser::Expat - Lowlevel access to James Clark's expat XML parser</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#methods">METHODS</a></li>
<ul>
<li><a href="#xml__parser__contentmodel_methods">XML::Parser::ContentModel Methods</a></li>
<li><a href="#xml__parser__expatnb_methods">XML::Parser::ExpatNB Methods</a></li>
</ul>
<li><a href="#functions">FUNCTIONS</a></li>
<li><a href="#authors">AUTHORS</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>XML::Parser::Expat - Lowlevel access to James Clark's expat XML parser</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">XML::Parser::Expat</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$parser</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">XML::Parser::Expat</span><span class="operator">;</span>
<span class="variable">$parser</span><span class="operator">-></span><span class="variable">setHandlers</span><span class="operator">(</span><span class="string">'Start'</span> <span class="operator">=></span> <span class="operator">\&</span><span class="variable">sh</span><span class="operator">,</span>
<span class="string">'End'</span> <span class="operator">=></span> <span class="operator">\&</span><span class="variable">eh</span><span class="operator">,</span>
<span class="string">'Char'</span> <span class="operator">=></span> <span class="operator">\&</span><span class="variable">ch</span><span class="operator">);</span>
<span class="keyword">open</span><span class="operator">(</span><span class="variable">FOO</span><span class="operator">,</span> <span class="string">'info.xml'</span><span class="operator">)</span> <span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Couldn't open"</span><span class="operator">;</span>
<span class="variable">$parser</span><span class="operator">-></span><span class="variable">parse</span><span class="operator">(</span><span class="variable">*FOO</span><span class="operator">);</span>
<span class="keyword">close</span><span class="operator">(</span><span class="variable">FOO</span><span class="operator">);</span>
<span class="comment"># $parser->parse('<foo id="me"> here <em>we</em> go </foo>');</span>
</pre>
<pre>
<span class="keyword">sub</span><span class="variable"> sh
</span><span class="operator">{</span>
<span class="keyword">my</span> <span class="operator">(</span><span class="variable">$p</span><span class="operator">,</span> <span class="variable">$el</span><span class="operator">,</span> <span class="variable">%atts</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">@_</span><span class="operator">;</span>
<span class="variable">$p</span><span class="operator">-></span><span class="variable">setHandlers</span><span class="operator">(</span><span class="string">'Char'</span> <span class="operator">=></span> <span class="operator">\&</span><span class="variable">spec</span><span class="operator">)</span>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">$el</span> <span class="keyword">eq</span> <span class="string">'special'</span><span class="operator">);</span>
<span class="operator">...</span>
<span class="operator">}</span>
</pre>
<pre>
<span class="keyword">sub</span><span class="variable"> eh
</span><span class="operator">{</span>
<span class="keyword">my</span> <span class="operator">(</span><span class="variable">$p</span><span class="operator">,</span> <span class="variable">$el</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">@_</span><span class="operator">;</span>
<span class="variable">$p</span><span class="operator">-></span><span class="variable">setHandlers</span><span class="operator">(</span><span class="string">'Char'</span> <span class="operator">=></span> <span class="operator">\&</span><span class="variable">ch</span><span class="operator">)</span> <span class="comment"># Special elements won't contain</span>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">$el</span> <span class="keyword">eq</span> <span class="string">'special'</span><span class="operator">);</span> <span class="comment"># other special elements</span>
<span class="operator">...</span>
<span class="operator">}</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module provides an interface to James Clark's XML parser, expat. As in
expat, a single instance of the parser can only parse one document. Calls
to parsestring after the first for a given instance will die.</p>
<p>Expat (and XML::Parser::Expat) are event based. As the parser recognizes
parts of the document (say the start or end of an XML element), then any
handlers registered for that type of an event are called with suitable
parameters.</p>
<p>
</p>
<hr />
<h1><a name="methods">METHODS</a></h1>
<dl>
<dt><strong><a name="item_new">new</a></strong>
<dd>
<p>This is a class method, the constructor for XML::Parser::Expat. Options are
passed as keyword value pairs. The recognized options are:</p>
</dd>
<ul>
<li><strong><a name="item_protocolencoding">ProtocolEncoding</a></strong>
<p>The protocol encoding name. The default is none. The expat built-in
encodings are: <code>UTF-8</code>, <code>ISO-8859-1</code>, <code>UTF-16</code>, and <code>US-ASCII</code>.
Other encodings may be used if they have encoding maps in one of the
directories in the @Encoding_Path list. Setting the protocol encoding
overrides any encoding in the XML declaration.</p>
</li>
<li><strong><a name="item_namespaces">Namespaces</a></strong>
<p>When this option is given with a true value, then the parser does namespace
processing. By default, namespace processing is turned off. When it is
turned on, the parser consumes <em>xmlns</em> attributes and strips off prefixes
from element and attributes names where those prefixes have a defined
namespace. A name's namespace can be found using the <a href="#item_namespace">namespace</a> method
and two names can be checked for absolute equality with the <a href="#item_eq_name">eq_name</a>
method.</p>
</li>
<li><strong><a name="item_noexpand">NoExpand</a></strong>
<p>Normally, the parser will try to expand references to entities defined in
the internal subset. If this option is set to a true value, and a default
handler is also set, then the default handler will be called when an
entity reference is seen in text. This has no effect if a default handler
has not been registered, and it has no effect on the expansion of entity
references inside attribute values.</p>
</li>
<li><strong><a name="item_stream_delimiter">Stream_Delimiter</a></strong>
<p>This option takes a string value. When this string is found alone on a line
while parsing from a stream, then the parse is ended as if it saw an end of
file. The intended use is with a stream of xml documents in a MIME multipart
format. The string should not contain a trailing newline.</p>
</li>
<li><strong><a name="item_errorcontext">ErrorContext</a></strong>
<p>When this option is defined, errors are reported in context. The value
of ErrorContext should be the number of lines to show on either side of
the line in which the error occurred.</p>
</li>
<li><strong><a name="item_parseparament">ParseParamEnt</a></strong>
<p>Unless standalone is set to "yes" in the XML declaration, setting this to
a true value allows the external DTD to be read, and parameter entities
to be parsed and expanded.</p>
</li>
<li><strong><a name="item_base">Base</a></strong>
<p>The base to use for relative pathnames or URLs. This can also be done by
using the base method.</p>
</li>
</ul>
<dt><strong><a name="item_sethandlers">setHandlers(TYPE, HANDLER [, TYPE, HANDLER [...]])</a></strong>
<dd>
<p>This method registers handlers for the various events. If no handlers are
registered, then a call to parsestring or parsefile will only determine if
the corresponding XML document is well formed (by returning without error.)
This may be called from within a handler, after the parse has started.</p>
</dd>
<dd>
<p>Setting a handler to something that evaluates to false unsets that
handler.</p>
</dd>
<dd>
<p>This method returns a list of type, handler pairs corresponding to the
input. The handlers returned are the ones that were in effect before the
call to setHandlers.</p>
</dd>
<dd>
<p>The recognized events and the parameters passed to the corresponding
handlers are:</p>
</dd>
<ul>
<li><strong><a name="item_start">Start (Parser, Element [, Attr, Val [,...]])</a></strong>
<p>This event is generated when an XML start tag is recognized. Parser is
an XML::Parser::Expat instance. Element is the name of the XML element that
is opened with the start tag. The Attr & Val pairs are generated for each
attribute in the start tag.</p>
</li>
<li><strong><a name="item_end">End (Parser, Element)</a></strong>
<p>This event is generated when an XML end tag is recognized. Note that
an XML empty tag (<foo/>) generates both a start and an end event.</p>
<p>There is always a lower level start and end handler installed that wrap
the corresponding callbacks. This is to handle the context mechanism.
A consequence of this is that the default handler (see below) will not
see a start tag or end tag unless the default_current method is called.</p>
</li>
<li><strong><a name="item_char">Char (Parser, String)</a></strong>
<p>This event is generated when non-markup is recognized. The non-markup
sequence of characters is in String. A single non-markup sequence of
characters may generate multiple calls to this handler. Whatever the
encoding of the string in the original document, this is given to the
handler in UTF-8.</p>
</li>
<li><strong><a name="item_proc">Proc (Parser, Target, Data)</a></strong>
<p>This event is generated when a processing instruction is recognized.</p>
</li>
<li><strong><a name="item_comment">Comment (Parser, String)</a></strong>
<p>This event is generated when a comment is recognized.</p>
</li>
<li><strong><a name="item_cdatastart">CdataStart (Parser)</a></strong>
<p>This is called at the start of a CDATA section.</p>
</li>
<li><strong><a name="item_cdataend">CdataEnd (Parser)</a></strong>
<p>This is called at the end of a CDATA section.</p>
</li>
<li><strong><a name="item_default">Default (Parser, String)</a></strong>
<p>This is called for any characters that don't have a registered handler.
This includes both characters that are part of markup for which no
events are generated (markup declarations) and characters that
could generate events, but for which no handler has been registered.</p>
<p>Whatever the encoding in the original document, the string is returned to
the handler in UTF-8.</p>
</li>
<li><strong><a name="item_unparsed">Unparsed (Parser, Entity, Base, Sysid, Pubid, Notation)</a></strong>
<p>This is called for a declaration of an unparsed entity. Entity is the name
of the entity. Base is the base to be used for resolving a relative URI.
Sysid is the system id. Pubid is the public id. Notation is the notation
name. Base and Pubid may be undefined.</p>
</li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -