``` Traceback (most recent call last): File "<tmp 1>", line 2, in <module> etree.fromstring('''<?xml version="1.0" encoding="UTF-8" standalone="no"?> File "src/lxml/etree.pyx", line 3428, in lxml.etree.fromstring File "src/lxml/parser.pxi", line 2066, in lxml.etree._parseMemoryDocument File "src/lxml/parser.pxi", line 1919, in lxml.etree._parseDoc File "src/lxml/parser.pxi", line 1944, in lxml.etree._parseDoc_bytes File "src/lxml/parser.pxi", line 1194, in lxml.etree._BaseParser._parseDoc File "src/lxml/parser.pxi", line 647, in lxml.etree._ParserContext._handleParseResultDoc File "src/lxml/parser.pxi", line 765, in lxml.etree._handleParseResult File "src/lxml/parser.pxi", line 689, in lxml.etree._raiseParseError File "<string>", line 2 lxml.etree.XMLSyntaxError: xmlParseCharRef: invalid xmlChar value 55357, line 2, column 24 ```
?
Feb 28, 3:02am
The error you're encountering is due to an invalid XML character reference in your string. Let's break down what's happening:
The Problem
The string b��c contains two XML character references: � and �.
These references correspond to Unicode code points U+D83D and U+DCA7, which are surrogate pairs used in UTF-16 encoding to represent characters outside the Basic Multilingual Plane (BMP), such as emojis.
In XML, character references must refer to valid Unicode code points. U+D83D is a high surrogate and U+DCA7 is a low surrogate. Surrogate pairs are not valid on their own in XML; they must be combined to form a single Unicode character (e.g., the emoji đź’Ą).
Why the Error?
XML parsers expect character references to refer to valid Unicode scalar values (i.e., code points that are not surrogate halves).
The parser sees � (U+D83D) and � (U+DCA7) as two separate, invalid references, hence the error:
xmlParseCharRef: invalid xmlChar value 55357
How to Fix It
You have two options:
1. Use the actual Unicode character (emoji) directly in your XML: