GNOME Bugzilla – Bug 326924
IsEmptyElement Followed by End Element
Last modified: 2021-07-05 13:26:46 UTC
Please describe the problem: readerForFile processes an XInclude under a Read() loop. A NodeType()==XML_READER_TYPE_ELEMENT is usually followed by a NodeType()==XML_READER_TYPE_END_ELEMENT, but not when IsEmptyElement() is True. However, in the included file, the END_ELEMENT *does* follow IsEmptyElement. I build a stack of nested element names. I push to the stack when the element is opened and pop from the stack when the element is closed. In between, I look at the state of the stack to determine whether I have come to an appropriate place in the document to do some additional processing. I don't know when to pop the closed element from the stack if it is an empty element. Steps to reproduce: Here are two input files and a Python script: o The first file is called welcome.xml. It contains an XInclude of the second file. <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" > <chapter id="welcome"> <?dbhtml filename="welcome.html"?> <title>Welcome to BLFS</title> <para>The Beyond Linux From Scratch book is designed to carry on from where the LFS book leaves off. But unlike the LFS book, it isn't designed to be followed straight through. Reading the <xref linkend="whichsections"/> part of this chapter should help guide you through the book.</para> <xi:include xmlns:xi="http://www.w3.org/2003/XInclude" href="conventions.xml"/> </chapter> o The second file is called conventions.xml. Each file contains an example of an empty element. <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" > <sect1 id="conventions"> <?dbhtml filename="conventions.html"?> <blockquote> <para>This form of text is used for several purposes in the book but mainly to emphasize important points or to give examples as to what to type.</para> </blockquote> <para><ulink url="http://www.linuxfromscratch.org/"/></para> </sect1> o The Python script is called TestIsEmptyElement.py. #!/usr/bin/python # TestIsEmptyElement.py # 2006 Jan 13 . ccr import libxml2 ZERO=0 __Flags=( libxml2.XML_PARSE_XINCLUDE| # Expand xincludes. libxml2.XML_PARSE_NOENT| # Expand entities. This doesn't look right. libxml2.XML_PARSE_NOBLANKS| # Suppress whitespace. ZERO) __Reader=libxml2.readerForFile('welcome.xml','ascii',__Flags) while __Reader.Read()==1: __Type=__Reader.NodeType() __Name=__Reader.Name() __IsEmpty=__Reader.IsEmptyElement() if __Type in [libxml2.XML_READER_TYPE_ELEMENT]: print "start %s: IsEmptyElement=%s"%(__Name,__IsEmpty) elif __Type in [libxml2.XML_READER_TYPE_END_ELEMENT]: print "end %s"%__Name # Fin Actual results: Here is the output from TestIsEmptyElement.py: start chapter: IsEmptyElement=0 start title: IsEmptyElement=0 end title start para: IsEmptyElement=0 start xref: IsEmptyElement=1 end para start sect1: IsEmptyElement=0 start blockquote: IsEmptyElement=0 start para: IsEmptyElement=0 end para end blockquote start para: IsEmptyElement=0 start ulink: IsEmptyElement=1 end ulink end para end sect1 end chapter Expected results: The <xref> element in welcome.xml is an empty element. The <ulink> element in conventions.xml is also an empty element, but it is follwed by an END_ELEMENT node, whereas <xref> is not. Does this happen every time? Yep. Other information: Nope.
The same problem is reported in bug #435187.
*** Bug 435187 has been marked as a duplicate of this bug. ***
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxml2/-/issues/ Thank you for your understanding and your help.