parse Method

This method parses the specified XML data.

Syntax

def parse() -> None: ...

Remarks

This method parses the specified XML data.

When parsing a document events will fire to provide information about the parsed data. After parse returns the document may be navigated by setting x_path if build_dom is True (default). If build_dom is False parsed data is only accessible through the events.

Events are fired only when qualifying conditions (such as, for example, the beginning of a new element) are met. In the meantime, text will be buffered internally. The following events will fire during parsing:

If build_dom is True (default), x_path may be set after this method returns. x_path implements a subset of the XML XPath specification, allowing you to point to specific elements in the XML documents.

The path is a series of one or more element accessors separated by '/'. The path can be absolute (starting with '/') or relative to the current x_path location.

The following are possible values for an element accessor:

'name'A particular element name
name[i]The i-th subelement of the current element with the given name
[i]The i-th subelement of the current element
[last()]The last subelement of the current element
[last()-i]The subelement located at the last location minus i in the current element
name[@attrname="attrvalue"]The subelement containing a particular value for a given attribute (supports single AND double quotes)
..The parent of the current element

When x_path is set to a valid path, x_element points to the name of the element, with x_parent, x_namespace, x_prefix, x_child_name, x_child_namespace, x_child_prefix, x_child_x_text, and x_text providing other properties of the element. The attributes of the current element are provided in the attr_name, attr_namespace, attr_prefix, and attr_value properties.

build_dom must be set to True prior to parsing the document for the x_path functionality to be available.

Example (Setting XPath):

Document rootXML.XPath = "/"
Specific ElementXML.XPath = "/root/SubElement1/SubElement2/"
i-th ChildXML.XPath = "/root/SubElement1[i]"

Input Properties

The class will determine the source of the input based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops.

If parsing multiple documents call reset between documents to reset the parser.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks 2020 Python Edition - Version 20.0 [Build 8307]