⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simple.html

📁 perl教程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<p>
</p>
<h2><a name="keeproot____1___in_out__handy">KeepRoot =&gt; 1 <em># in+out - handy</em></a></h2>
<p>In its attempt to return a data structure free of superfluous detail and
unnecessary levels of indirection, <code>XMLin()</code> normally discards the root
element name.  Setting the 'KeepRoot' option to '1' will cause the root element
name to be retained.  So after executing this code:</p>
<pre>
  $config = XMLin('&lt;config tempdir=&quot;/tmp&quot; /&gt;', KeepRoot =&gt; 1)</pre>
<p>You'll be able to reference the tempdir as
<code>$config-&gt;{config}-&gt;{tempdir}</code> instead of the default
<code>$config-&gt;{tempdir}</code>.</p>
<p>Similarly, setting the 'KeepRoot' option to '1' will tell <code>XMLout()</code> that the
data structure already contains a root element name and it is not necessary to
add another.</p>
<p>
</p>
<h2><a name="keyattr______list_____in_out__important">KeyAttr =&gt; [ list ] <em># in+out - important</em></a></h2>
<p>This option controls the 'array folding' feature which translates nested
elements from an array to a hash.  It also controls the 'unfolding' of hashes
to arrays.</p>
<p>For example, this XML:</p>
<pre>
    &lt;opt&gt;
      &lt;user login=&quot;grep&quot; fullname=&quot;Gary R Epstein&quot; /&gt;
      &lt;user login=&quot;stty&quot; fullname=&quot;Simon T Tyson&quot; /&gt;
    &lt;/opt&gt;</pre>
<p>would, by default, parse to this:</p>
<pre>
    <span class="operator">{</span>
      <span class="string">'user'</span> <span class="operator">=&gt;</span> <span class="operator">[</span>
                  <span class="operator">{</span>
                    <span class="string">'login'</span> <span class="operator">=&gt;</span> <span class="string">'grep'</span><span class="operator">,</span>
                    <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Gary R Epstein'</span>
                  <span class="operator">}</span><span class="operator">,</span>
                  <span class="operator">{</span>
                    <span class="string">'login'</span> <span class="operator">=&gt;</span> <span class="string">'stty'</span><span class="operator">,</span>
                    <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Simon T Tyson'</span>
                  <span class="operator">}</span>
                <span class="operator">]</span>
    <span class="operator">}</span>
</pre>
<p>If the option 'KeyAttr =&gt; &quot;login&quot;' were used to specify that the 'login'
attribute is a key, the same XML would parse to:</p>
<pre>
    <span class="operator">{</span>
      <span class="string">'user'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                  <span class="string">'stty'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                              <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Simon T Tyson'</span>
                            <span class="operator">}</span><span class="operator">,</span>
                  <span class="string">'grep'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                              <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Gary R Epstein'</span>
                            <span class="operator">}</span>
                <span class="operator">}</span>
    <span class="operator">}</span>
</pre>
<p>The key attribute names should be supplied in an arrayref if there is more
than one.  <code>XMLin()</code> will attempt to match attribute names in the order
supplied.  <code>XMLout()</code> will use the first attribute name supplied when
'unfolding' a hash into an array.</p>
<p>Note 1: The default value for 'KeyAttr' is ['name', 'key', 'id'].  If you do
not want folding on input or unfolding on output you must setting this option
to an empty list to disable the feature.</p>
<p>Note 2: If you wish to use this option, you should also enable the
<code>ForceArray</code> option.  Without 'ForceArray', a single nested element will be
rolled up into a scalar rather than an array and therefore will not be folded
(since only arrays get folded).</p>
<p>
</p>
<h2><a name="keyattr______list_____in_out__important">KeyAttr =&gt; { list } <em># in+out - important</em></a></h2>
<p>This alternative (and preferred) method of specifiying the key attributes
allows more fine grained control over which elements are folded and on which
attributes.  For example the option 'KeyAttr =&gt; { package =&gt; 'id' } will cause
any package elements to be folded on the 'id' attribute.  No other elements
which have an 'id' attribute will be folded at all.</p>
<p>Note: <code>XMLin()</code> will generate a warning (or a fatal error in <a href="#strict_mode">STRICT MODE</a>)
if this syntax is used and an element which does not have the specified key
attribute is encountered (eg: a 'package' element without an 'id' attribute, to
use the example above).  Warnings will only be generated if <strong>-w</strong> is in force.</p>
<p>Two further variations are made possible by prefixing a '+' or a '-' character
to the attribute name:</p>
<p>The option 'KeyAttr =&gt; { user =&gt; &quot;+login&quot; }' will cause this XML:</p>
<pre>
    &lt;opt&gt;
      &lt;user login=&quot;grep&quot; fullname=&quot;Gary R Epstein&quot; /&gt;
      &lt;user login=&quot;stty&quot; fullname=&quot;Simon T Tyson&quot; /&gt;
    &lt;/opt&gt;</pre>
<p>to parse to this data structure:</p>
<pre>
    <span class="operator">{</span>
      <span class="string">'user'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                  <span class="string">'stty'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                              <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Simon T Tyson'</span><span class="operator">,</span>
                              <span class="string">'login'</span>    <span class="operator">=&gt;</span> <span class="string">'stty'</span>
                            <span class="operator">}</span><span class="operator">,</span>
                  <span class="string">'grep'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                              <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Gary R Epstein'</span><span class="operator">,</span>
                              <span class="string">'login'</span>    <span class="operator">=&gt;</span> <span class="string">'grep'</span>
                            <span class="operator">}</span>
                <span class="operator">}</span>
    <span class="operator">}</span>
</pre>
<p>The '+' indicates that the value of the key attribute should be copied rather
than moved to the folded hash key.</p>
<p>A '-' prefix would produce this result:</p>
<pre>
    <span class="operator">{</span>
      <span class="string">'user'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                  <span class="string">'stty'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                              <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Simon T Tyson'</span><span class="operator">,</span>
                              <span class="string">'-login'</span>    <span class="operator">=&gt;</span> <span class="string">'stty'</span>
                            <span class="operator">}</span><span class="operator">,</span>
                  <span class="string">'grep'</span> <span class="operator">=&gt;</span> <span class="operator">{</span>
                              <span class="string">'fullname'</span> <span class="operator">=&gt;</span> <span class="string">'Gary R Epstein'</span><span class="operator">,</span>
                              <span class="string">'-login'</span>    <span class="operator">=&gt;</span> <span class="string">'grep'</span>
                            <span class="operator">}</span>
                <span class="operator">}</span>
    <span class="operator">}</span>
</pre>
<p>As described earlier, <code>XMLout</code> will ignore hash keys starting with a '-'.</p>
<p>
</p>
<h2><a name="noattr____1___in_out__handy">NoAttr =&gt; 1 <em># in+out - handy</em></a></h2>
<p>When used with <code>XMLout()</code>, the generated XML will contain no attributes.
All hash key/values will be represented as nested elements instead.</p>
<p>When used with <code>XMLin()</code>, any attributes in the XML will be ignored.</p>
<p>
</p>
<h2><a name="noescape____1___out__seldom_used">NoEscape =&gt; 1 <em># out - seldom used</em></a></h2>
<p>By default, <code>XMLout()</code> will translate the characters '&lt;', '&gt;', '&amp;' and
'&quot;' to '&amp;lt;', '&amp;gt;', '&amp;amp;' and '&amp;quot' respectively.  Use this option to
suppress escaping (presumably because you've already escaped the data in some
more sophisticated manner).</p>
<p>
</p>
<h2><a name="noindent____1___out__seldom_used">NoIndent =&gt; 1 <em># out - seldom used</em></a></h2>
<p>Set this option to 1 to disable <code>XMLout()</code>'s default 'pretty printing' mode.
With this option enabled, the XML output will all be on one line (unless there
are newlines in the data) - this may be easier for downstream processing.</p>
<p>
</p>
<h2><a name="nosort____1___out__seldom_used">NoSort =&gt; 1 <em># out - seldom used</em></a></h2>
<p>Newer versions of XML::Simple sort elements and attributes alphabetically (*),
by default.  Enable this option to suppress the sorting - possibly for
backwards compatibility.</p>
<p>* Actually, sorting is alphabetical but 'key' attribute or element names (as in
'KeyAttr') sort first.  Also, when a hash of hashes is 'unfolded', the elements
are sorted alphabetically by the value of the key field.</p>
<p>
</p>
<h2><a name="normalisespace____0___1___2___in__handy">NormaliseSpace =&gt; 0 | 1 | 2 <em># in - handy</em></a></h2>
<p>This option controls how whitespace in text content is handled.  Recognised
values for the option are:</p>
<ul>
<li>
<p>0 = (default) whitespace is passed through unaltered (except of course for the
normalisation of whitespace in attribute values which is mandated by the XML
recommendation)</p>
</li>
<li>
<p>1 = whitespace is normalised in any value used as a hash key (normalising means
removing leading and trailing whitespace and collapsing sequences of whitespace
characters to a single space)</p>
</li>
<li>
<p>2 = whitespace is normalised in all text content</p>
</li>
</ul>
<p>Note: you can spell this option with a 'z' if that is more natural for you.</p>
<p>
</p>
<h2><a name="nsexpand____1___in_out_handy__sax_only">NSExpand =&gt; 1 <em># in+out handy - SAX only</em></a></h2>
<p>This option controls namespace expansion - the translation of element and
attribute names of the form 'prefix:name' to '{uri}name'.  For example the
element name 'xsl:template' might be expanded to:
'{http://www.w3.org/1999/XSL/Transform}template'.</p>
<p>By default, <code>XMLin()</code> will return element names and attribute names exactly as
they appear in the XML.  Setting this option to 1 will cause all element and
attribute names to be expanded to include their namespace prefix.</p>
<p><em>Note: You must be using a SAX parser for this option to work (ie: it does not
work with XML::Parser)</em>.</p>
<p>This option also controls whether <code>XMLout()</code> performs the reverse translation
from '{uri}name' back to 'prefix:name'.  The default is no translation.  If
your data contains expanded names, you should set this option to 1 otherwise
<code>XMLout</code> will emit XML which is not well formed.</p>
<p><em>Note: You must have the XML::NamespaceSupport module installed if you want
<code>XMLout()</code> to translate URIs back to prefixes</em>.</p>
<p>
</p>
<h2><a name="numericescape____0___1___2___out__handy">NumericEscape =&gt; 0 | 1 | 2 <em># out - handy</em></a></h2>
<p>Use this option to have 'high' (non-ASCII) characters in your Perl data
structure converted to numeric entities (eg: &amp;#8364;) in the XML output.  Three
levels are possible:</p>
<p>0 - default: no numeric escaping (OK if you're writing out UTF8)</p>
<p>1 - only characters above 0xFF are escaped (ie: characters in the 0x80-FF range are not escaped), possibly useful with ISO8859-1 output</p>
<p>2 - all characters above 0x7F are escaped (good for plain ASCII output)</p>
<p>
</p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -