Dear Stefan,<br><br>I&#39;ve tried the method you&#39;ve suggested below, but it isn&#39;t quite working for me. It may be that I&#39;ve misunderstood your suggestion. I&#39;ll explain what I&#39;ve tried. Here is my python program, extract_links_dmoz.py:<br>
<br>from lxml import etree<br>infile = open(&quot;content.example.xml&quot;, &quot;r&quot;)<br>infile.seek(0)<br>outfile = open(&quot;output_test001.txt&quot;, &quot;w&quot;)<br>class EchoTarget():<br>&nbsp;&nbsp;&nbsp; def start(self, tag, attrib):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if tag.endswith(&quot;xternalPage&quot;):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line = attrib[&quot;about&quot;]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if line != &quot;&quot;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outfile.write(line+&quot;\n&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print line<br>
&nbsp;&nbsp;&nbsp; def close(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &quot;closed!&quot;<br>parser = etree.XMLParser(target = EchoTarget())<br>result = etree.XML(infile.read(), parser)<br><br>This uses the short, example RDF file at <a href="http://rdf.dmoz.org/rdf/content.example.txt">http://rdf.dmoz.org/rdf/content.example.txt</a> (which I have renamed content.example.xml), and works fine. When I view the output_test001.txt file, it contains one URL per line, which is exactly what I want for now.<br>
<br>However, if I change the program to read content.rdf.u8.xml (i.e. the full-length DMOZ links file from <a href="http://rdf.dmoz.org/rdf/content.rdf.u8.gz">http://rdf.dmoz.org/rdf/content.rdf.u8.gz</a>) instead of content.example.xml , then when I run the program I get the following error:<br>
<br>Traceback (most recent call last):<br>&nbsp; File &quot;extract_links_dmoz.py&quot;, line 26, in &lt;module&gt;<br>&nbsp;&nbsp;&nbsp; result = etree.XML(infile.read(), parser)<br>MemoryError<br><br>Any help you (or others) can offer would be greatly appreciated.<br>
<br>Many thanks,<br><br>Sam<br><br><div class="gmail_quote">2008/5/22 Stefan Behnel &lt;<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<div><div></div><div class="Wj3C7c"><br>
Sam Kuper wrote:<br>
&gt; Gosh, this is turning into a really fragmented post; apologies. I meant to<br>
&gt; add to the first post that once parsed, my intention was to run a fairly<br>
&gt; simple XSL transform on the document, to extract a copy of each of the URLs<br>
&gt; it contains. Probably something like this:<br>
&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>
&gt; &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;<br>
&gt; <a href="http://www.w3.org/1999/XSL/Transform" target="_blank">http://www.w3.org/1999/XSL/Transform</a>&quot;&gt;<br>
&gt; &nbsp; &nbsp; &lt;xsl:template match=&quot;/&quot;&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;html&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;body&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h2&gt;ODP URLs&lt;/h2&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;xsl:for-each select=&quot;Topic/link&quot;&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;p&gt;&lt;xsl:value-of select=&quot;@r:resource&quot;/&gt;&lt;/p&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/xsl:for-each&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/body&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/html&gt;<br>
&gt; &nbsp; &nbsp; &lt;/xsl:template&gt;<br>
&gt; &lt;/xsl:stylesheet&gt;<br>
<br>
</div></div>That is a problem that can be solved with extremely little memory. Take a look<br>
at the (SAX-like) target parser interface, which will not build a tree and<br>
instead just receive callbacks while parsing:<br>
<br>
 &nbsp;<a href="http://codespeak.net/lxml/dev/parsing.html#the-target-parser-interface" target="_blank">http://codespeak.net/lxml/dev/parsing.html#the-target-parser-interface</a><br>
<br>
Write a parser target class that keeps track of being inside or outside the<br>
&quot;Topic&quot; tag (start/end), and whenever you find a &quot;link&quot; tag while inside a<br>
&quot;Topic&quot; tag, look for a &quot;{whatever-namespace}resource&quot; attribute in the attrib<br>
dictionary and and write it into a hand-generated HTML stream like the one you<br>
used above.<br>
<font color="#888888"><br>
Stefan<br>
</font></blockquote></div><br><br>