MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / XMLParser

Class XMLParser

tools/python-3.11.9-amd64/Lib/xml/etree/ElementTree.py:1518–1750  ·  view source on GitHub ↗

Element structure builder for XML source data based on the expat parser. *target* is an optional target object which defaults to an instance of the standard TreeBuilder class, *encoding* is an optional encoding string which if given, overrides the encoding specified in the XML file:

Source from the content-addressed store, hash-verified

1516
1517# also see ElementTree and TreeBuilder
1518class XMLParser:
1519 """Element structure builder for XML source data based on the expat parser.
1520
1521 *target* is an optional target object which defaults to an instance of the
1522 standard TreeBuilder class, *encoding* is an optional encoding string
1523 which if given, overrides the encoding specified in the XML file:
1524 http://www.iana.org/assignments/character-sets
1525
1526 """
1527
1528 def __init__(self, *, target=None, encoding=None):
1529 try:
1530 from xml.parsers import expat
1531 except ImportError:
1532 try:
1533 import pyexpat as expat
1534 except ImportError:
1535 raise ImportError(
1536 "No module named expat; use SimpleXMLTreeBuilder instead"
1537 )
1538 parser = expat.ParserCreate(encoding, "}")
1539 if target is None:
1540 target = TreeBuilder()
1541 # underscored names are provided for compatibility only
1542 self.parser = self._parser = parser
1543 self.target = self._target = target
1544 self._error = expat.error
1545 self._names = {} # name memo cache
1546 # main callbacks
1547 parser.DefaultHandlerExpand = self._default
1548 if hasattr(target, 'start'):
1549 parser.StartElementHandler = self._start
1550 if hasattr(target, 'end'):
1551 parser.EndElementHandler = self._end
1552 if hasattr(target, 'start_ns'):
1553 parser.StartNamespaceDeclHandler = self._start_ns
1554 if hasattr(target, 'end_ns'):
1555 parser.EndNamespaceDeclHandler = self._end_ns
1556 if hasattr(target, 'data'):
1557 parser.CharacterDataHandler = target.data
1558 # miscellaneous callbacks
1559 if hasattr(target, 'comment'):
1560 parser.CommentHandler = target.comment
1561 if hasattr(target, 'pi'):
1562 parser.ProcessingInstructionHandler = target.pi
1563 # Configure pyexpat: buffering, new-style attribute handling.
1564 parser.buffer_text = 1
1565 parser.ordered_attributes = 1
1566 self._doctype = None
1567 self.entity = {}
1568 try:
1569 self.version = "Expat %d.%d.%d" % expat.version_info
1570 except AttributeError:
1571 pass # unknown
1572
1573 def _setevents(self, events_queue, events_to_report):
1574 # Internal API for XMLPullParser
1575 # events_to_report: a list of events to report during parsing (same as

Callers 6

parseMethod · 0.85
__init__Method · 0.85
XMLFunction · 0.85
XMLIDFunction · 0.85
fromstringlistFunction · 0.85
canonicalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected