Module etree syntax error

Would someone please explain the following syntax error that appears when importing the etree module:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
from lxml import etree parser = etree.XMLParser() tree = etree.XML("<root></b>", parser)
Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> tree = etree.XML("<root></b>", parser) File "lxml.etree.pyx", line 2723, in lxml.etree.XML (src/lxml/lxml.etree.c:52448) File "parser.pxi", line 1573, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:79932) File "parser.pxi", line 1452, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:78774) File "parser.pxi", line 960, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:75389) File "parser.pxi", line 564, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:71739) File "parser.pxi", line 645, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:72614) File "parser.pxi", line 585, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:71955) XMLSyntaxError: Opening and ending tag mismatch: root line 1 and b, line 1, column 11

On 8/29/2011 10:56, Michael McLoughlin wrote:
Would someone please explain the following syntax error that appears when importing the etree module:
tree = etree.XML("<root></b>", parser)
"<root></b>" is invalid XML. Tags must be balanced, so you have to have either matched opening & closing tags, or a standalone tag (<b/>). You also don't need to manually instantiate a parser, unless you're setting some non-default options. Something similar would be:
from lxml import etree tree = etree.XML("<root><b/></root>")
I'd recommend reading up on the basics of XML, something like http://www.w3schools.com/xml/default.asp
Jason
participants (3)
-
Jason Viers
-
Michael McLoughlin
-
Sérgio Basto