Re: message still not working with xslt?
Paul Tremblay <paulhtremblay <at> gmail.com>
2011-02-05 03:10:51 GMT
On 2/4/11 3:05 AM, Stefan Behnel wrote:
>
> http://codespeak.net/lxml/dev/api/lxml.etree._LogEntry-class.html
> http://codespeak.net/lxml/dev/api/lxml.etree._ErrorLog-class.html
>
> Sorry for the lack of API documentation. Cython doesn't currently
> support attaching a docstring to an automatically generated property
> (this has been an often requested feature but no-one has taken care of
> it so far). But I'll add at least a doc comment to the _LogEntry class.
>
> As always, documentation fixes are always welcome.
>
> http://codespeak.net/svn/lxml/trunk/doc/
>
>
Here's a documentation fix. I'm not sure about some of the properties,
such as level, etc.
Error log
---------
Parsers have an ``error_log`` property that lists the errors of the
last parser run. Each ``error_log`` is a list, and each item in the
list is an object that has the following properties:
* ``columns``: an integer that identifies the column where the error
occurred.
* ``domain``: a unicode string
* ``filename``: a unicode string
* ``level``: an integer
* ``level_name``: an integer
* ``line``: a unicode string that identifies the line where the error
occurred.
* ``message``: a unicode string that lists the message.
* ``type``: an integer
* ``type_name``: a unicode string
.. sourcecode:: pycon
>>> parser = etree.XMLParser()
>>> print(len(parser.error_log))
0
>>> tree = etree.XML("<root></b>", parser)
Traceback (most recent call last):
...
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: root line
1 and b, line 1, column 11
>>> print(len(parser.error_log))
1
>>> error = parser.error_log[0]
>>> print(error.message)
Opening and ending tag mismatch: root line 1 and b
>>> print(error.line)
1
>>> print(error.column)
11
The following code shows how to output messages from xsl:message when
processing XSl.
.. sourcecode:: pycon
>>> f = StringIO('''
... <xsl:stylesheet
... xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
... xmlns:fo="http://www.w3.org/1999/XSL/Format"
... version="1.1"
... >
... <xsl:template match="root">
... <xsl:message >
... <xsl:text>found root</xsl:text>
... </xsl:message>
... <xsl:apply-templates/>
... </xsl:template>
...
... <xsl:template match="para">
... <xsl:message >
... <xsl:text>found para</xsl:text>
... </xsl:message>
... </xsl:template>
... </xsl:stylesheet>
...
... ''')
>>> xslt_doc = etree.parse(f)
>>> transform = etree.XSLT(xslt_doc)
>>> f = StringIO('<root><para>Text</para></root>')
>>> doc = etree.parse(f)
>>> result_tree = transform(doc)
>>> for error in transform.error_log:
... print 'message from line %s, col %s:' % (error.line, error.column)
... print error.message
... print
... print 'domain_name: %s' % error.domain_name
... print 'filename: %s' % error.filename
... print 'level: %s' % error.level
... print 'level_name: %s' % error.level_name
... print 'type: %s' % error.type
... print 'type_name: %s' % error.type_name
... print '================================================='
message from line 0, col 0:
found root
domain_name: XSLT
filename: <string>
level: 2
level_name: ERROR
type: 0
type_name: ERR_OK
=================================================
message from line 0, col 0:
found para
domain_name: XSLT
filename: <string>
level: 2
level_name: ERROR
type: 0
type_name: ERR_OK
=================================================