Note that there are some explanatory texts on larger screens.

plurals
  1. POpreserve entity references when parsing xml
    text
    copied!<p>Running the following simple script:</p> <pre><code>from lxml import etree tree = etree.parse('VimKeys.xml') root = tree.getroot() for child in root: print ("&lt;table&gt;") print ("&lt;caption&gt;" + child.attrib['title'] + "&lt;/caption&gt;") for child in child: print ("&lt;tr&gt;") print ("&lt;th&gt;" + child.text + "&lt;/th&gt;") print ("&lt;td&gt;" + child.attrib['description'] + "&lt;/td&gt;") print ("&lt;/tr&gt;") print ("&lt;/table&gt;") </code></pre> <p>against the following xml:</p> <pre><code>&lt;keycommands&gt; &lt;category title="Editing"&gt; &lt;key description="replace"&gt;r&lt;/key&gt; &lt;key description="change, line"&gt;c,cc&lt;/key&gt; &lt;key description="join line with the following"&gt;J&lt;/key&gt; &lt;key description="delete &amp;amp; insert"&gt;s&lt;/key&gt; &lt;key description="change case"&gt;~&lt;/key&gt; &lt;key description="apply last edit"&gt;.&lt;/key&gt; &lt;key description="undo, redo"&gt;u,⌃+r&lt;/key&gt; &lt;key description="indent line right, left"&gt;&amp;gt;&amp;gt;,&amp;lt;&amp;lt;&lt;/key&gt; &lt;key description="auto-indent line"&gt;==&lt;/key&gt; &lt;/category&gt; &lt;/keycommands&gt; </code></pre> <p>results in the following:</p> <pre><code>&lt;caption&gt;Editing&lt;/caption&gt; &lt;tr&gt; &lt;th&gt;r&lt;/th&gt; &lt;td&gt;replace&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;c,cc&lt;/th&gt; &lt;td&gt;change, line&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;J&lt;/th&gt; &lt;td&gt;join line with the following&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;s&lt;/th&gt; &lt;td&gt;delete &amp; insert&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;~&lt;/th&gt; &lt;td&gt;change case&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;.&lt;/th&gt; &lt;td&gt;apply last edit&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;u,⌃+r&lt;/th&gt; &lt;td&gt;undo, redo&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;&gt;&gt;,&lt;&lt;&lt;/th&gt; &lt;td&gt;indent line right, left&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;==&lt;/th&gt; &lt;td&gt;auto-indent line&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>which is invalid HTML due to the less than and greater than signs which were referenced as </p> <pre><code>&amp;lt; and &amp;gt; </code></pre> <p>in the source document.</p> <p>How can I preserve these in the final product?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload