Kun JIN | 30 Sep 10:07 2014
Picon

How to use result of nsmap in xpath

hello,

"nsmap" is an lxml.element function to get namespaces of the element, 
usually, a None type will be returned, like:

{'olac': 'http://www.language-archives.org/OLAC/1.1/', None: 
'http://www.imsglobal.org/xsd/imscp_v1p1'}

i want use this namespaces in XPath, but i got an error:
TypeError: empty namespace prefix is not supported in XPath

so, i must delete this NoneType by creating a new dictionay in Python:

dic_ns = {}
for element in root.nsmap:
     if element is None: continue
     dic_ns[element] = root.nsmap[element]

QUESTION: is there some other methods to do this?

Thank you in advance,

Bests,

Kun

_________________________________________________________________
Mailing list for the lxml Python XML toolkit - http://lxml.de/
lxml <at> lxml.de
https://mailman-mail5.webfaction.com/listinfo/lxml
(Continue reading)

Charlie Clark | 24 Sep 11:45 2014
Picon

Best way of dealing with empty attributes

Hi,

we often have the case where element attributes may turn out to be None.  
This leads to an error in lxml when creating an Element, or serialising it  
in ElementTree. Is it possible to configure the behaviour is such  
situations? Either to ignore the attribute or just create it with no value?

Charlie
--

-- 
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
_________________________________________________________________
Mailing list for the lxml Python XML toolkit - http://lxml.de/
lxml <at> lxml.de
https://mailman-mail5.webfaction.com/listinfo/lxml
tcqwerty | 23 Sep 23:48 2014

possible bug: parse() and fromstring() have different results

Basically, I would expect ET.parse(StringIO(test_string)) and
ET.fromstring(test_string) to return the same data. Instead, parse()
returns an ElementTree, and fromstring() returns an Element.
----
from StringIO import StringIO
from lxml import etree as ET
test_string = """<root>data</root>"""
tree1 = ET.parse(StringIO(test_string))
tree2 = ET.fromstring(test_string)
print ET.tostring(tree1), type(tree1)
print ET.tostring(tree2), type(tree2)
----
Output:
<root>data</root> <type 'lxml.etree._ElementTree'>
<root>data</root> <type 'lxml.etree._Element'>

_________________________________________________________________
Mailing list for the lxml Python XML toolkit - http://lxml.de/
lxml <at> lxml.de
https://mailman-mail5.webfaction.com/listinfo/lxml
Patrick Asselman | 21 Sep 22:53 2014
Picon

(no subject)

Can somebody please shed some light on what is going on here?

Lxml seems to be installed according to pip:

$ pip freeze
lxml==3.4.0

But for some reason it is not found by Python:

$ python3
Python 3.4.0 (v3.4.0:04f714765c13, Mar 15 2014, 23:02:41) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ImportError: No module named 'lxml'
>>>

Also help('modules') doesn't show lxml in the list.

This is on OSX 10.9.5

Before this, I install py34-lxml through macports and it said "Installing py34-lxml  <at> 3.3.5_0", which
made me think it was installing an older version, so I chose to uninstall and use pip instead. Pip completes
the installation succesfully, but the module cannot be found by Python. Any suggestions?

Best regards, 
Patrick
_________________________________________________________________
(Continue reading)

Charlie Clark | 19 Sep 20:23 2014
Hi,

I'm trying to build lxml from source on Mac OS (it builds fine as a
dependency) but I seem to be hitting a wall:

Trying to build without Cython, but pre-generated 'src/lxml/lxml.etree.c'

I get this whether or not I'm using Cython (it's installed) or python
setup.py build --static-deps

libxml2 and libxlst are installed.

Charlie
--

-- 
Charlie Clark
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-938-5360
Mobile: +49-178-782-6226
_________________________________________________________________
Mailing list for the lxml Python XML toolkit - http://lxml.de/
lxml <at> lxml.de
https://mailman-mail5.webfaction.com/listinfo/lxml
Burak Arslan | 16 Sep 10:12 2014
Picon

missing void elements

Hello,

Where's the lxml issue tracker? I couldn't find it?

Void elements are html tags that don't need a closing tag. <br> is a
well known example:

>>> from lxml.builder import E
>>> html.tostring(E.br())
'<br>'
>>> etree.tostring(E.br())
'<br/>'
>>>

<p> is not a void element, so:

>>> html.tostring(E.p())
'<p></p>'
>>> etree.tostring(E.p())
'<p/>'

see the full list:

http://www.w3.org/TR/html5/syntax.html#elements-0

While working on etree.htmlfile, I noticed that the following tags are
not treated as void:

embed, keygen, source, track, wbr

(Continue reading)

Stefan Behnel | 10 Sep 19:19 2014
Picon

lxml 3.4.0 released

Hi all,

I just released the final version of lxml 3.4, with no code changes since
the last beta. This is a feature release that mostly cleans up some prior
deficiencies and speeds up parsing for documents that contain XML-IDs.

Note that this release drops support for older Python versions and now
requires Py2.6/7 or Py3.2+. It also removes support for very old versions
of libxml2 and libxslt (<=2008).

The documentation is here: http://lxml.de/

Download:  http://lxml.de/files/lxml-3.4.0.tgz

Signature: http://lxml.de/files/lxml-3.4.0.tgz.asc

Changelog: http://lxml.de/3.4/changes-3.4.0.html

Github:
https://github.com/lxml/lxml/blob/14505bc62f5f1fc9fb0ff007955f3e67ab4562bb

This release was built using Cython 0.21, but should also build fine with
0.20.x.

If you are interested in commercial support or customisations for the lxml
package, please contact me directly.

Have fun,

Stefan
(Continue reading)

Charlie Clark | 10 Sep 12:17 2014
Picon

Comparing XML requires unicode?

Hi,

last year Stefan very kindly showed me how to use LXMLOutputchecker to  
compare XML trees. This is a lifesaver if you generate a lot of XML and  
want to check it: we're using it extensively in openpyxl.

But recently I've found myself bashing my head against it repeatedly as it  
seems to work with unicode only, which means I can't simply use  
compare_xml(tostring(tree), expected) - wrapper function from
https://bitbucket.org/openpyxl/openpyxl/src/03cb2a7f046d02ec3a19cbeba4375b6d6a19db73/openpyxl/tests/helper.py?at=default#cl-68

I can work around this using a helper function or lxml's handy  
tounicode(), except that we also need to run tests assuming lxml is not  
installed.

Am I missing something simple?

Charlie
--

-- 
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
_________________________________________________________________
Mailing list for the lxml Python XML toolkit - http://lxml.de/
(Continue reading)

Stefan Behnel | 5 Sep 15:35 2014
Picon

lxml 3.4.0 beta 1 released

Hi all,

I just released the first beta version of the upcoming lxml 3.4. This is a
feature release that mostly cleans up some prior deficiencies and speeds up
parsing for documents that contain XML-IDs. Please give it some testing
against your code.

Note that this release drops support for older Python versions and now
requires Py2.6/7 or Py3.2+. It also removes support for very old versions
of libxml2 and libxslt (<=2008).

The documentation is here: http://lxml.de/

Download:  http://lxml.de/files/lxml-3.4.0beta1.tgz

Signature: http://lxml.de/files/lxml-3.4.0beta1.tgz.asc

Changelog: http://lxml.de/3.4/changes-3.4.0beta1.html

Github:
https://github.com/lxml/lxml/commit/638b9ce006ba32e46a09101e15c93ee94649a2ae

This release was built using a pre-release version of Cython 0.21
(7a47dfdabcb9a9861480b1437f092c5f84911558). The final release is expected
to use Cython 0.21 (but should build just fine with 0.20.x).

If you are interested in commercial support or customisations for the lxml
package, please contact me directly.

Have fun,
(Continue reading)

D.H.J. Takken | 3 Sep 14:46 2014
Picon
Picon

Incremental Serialisation: Output buffering

Hello,

I am attempting to use etree.xmlfile to incrementally generate an XML
stream into a file-like object, but I ran into a buffering problem. It
looks like etree.xmlfile does not write straight into the supplied
output, but is buffering internally. I searched for a way to force
flushing the generated XML into the output, but did not find any.

Looking at the source code, I see only one call to
xmlOutputBufferFlush() and - as far as I can see - it is not called
during incremental serialisation.

Is my assumption about internal buffering correct? Is there a way to
flush the internal buffer?

Thanks a lot for helping me out!
_________________________________________________________________
Mailing list for the lxml Python XML toolkit - http://lxml.de/
lxml <at> lxml.de
https://mailman-mail5.webfaction.com/listinfo/lxml
Alan Evangelista | 28 Aug 20:42 2014
Picon

Unexpected output when using xpath() twice

When I try to use xpath() method twice, I get unexpected outputs.

 >>> from lxml import etree
 >>> xml_systems = etree.fromstring("<systems><system 
name='gekko1'/><system name='gekko2'/></systems>")
# get all nodes with name 'system' which are children of root node 'systems'
 >>> xml_system_list = xml_systems.xpath("/systems/system")
 >>> etree.tostring(xml_system_list[0])
'<system name="gekko1"/>'
 >>> etree.tostring(xml_system_list[1])
'<system name="gekko2"/>'
# get 'name' attribute of all 'system's nodes in the hierarchy
 >>> xml_system_list[0].xpath("//system/ <at> name")
['gekko1', 'gekko2']
# get 'name' attribute of root node 'system'
 >>> xml_system_list[0].xpath("/system/ <at> name")
[]

I expected 'gekko1' string as output in two last commands.
Maybe I have not understood the API correctly? What should
I do to get the behavior I expect?

FYI if I convert xml_system_list[0] to string and convert it back to XML
using tostring() and fromstring(), I get the expected output.

Regards,
Alan Evangelista

_________________________________________________________________
Mailing list for the lxml Python XML toolkit - http://lxml.de/
(Continue reading)


Gmane