XmlSaxHandler

class xsdata.formats.dataclass.parsers.handlers.XmlSaxHandler(parser, clazz)[source]

Sax content handler based on native python.

Parameters
  • parser (PushParser) – The parser instance to feed with events

  • clazz (Optional[Type]) – The target binding model, auto located if omitted.

parse(source)[source]

Parse an XML document from a system identifier or an InputSource.

Raises

XmlHandlerError – If process xinclude config is enabled.

Parameters

source (Any) –

Return type

Any

startElementNS(name, qname, attrs)[source]

Start element notification receiver.

The receiver will flush any previous active element, append a new data frame to collect data content for the next active element and notify the main parser to prepare for next binding instruction.

Converts name and attribute keys to fully qualified tags to respect the main parser api, eg (foo, bar) -> {foo}bar

Parameters
endElementNS(name, qname)[source]

End element notification receiver.

The receiver will flush any previous active element and set the next element to be flushed.

Converts name and attribute keys to fully qualified tags to respect the ain parser api, eg (foo, bar) -> {foo}bar

Parameters
  • name (Tuple) – Namespace-name tuple

  • qname (Any) – Not used

characters(content)[source]

Proxy for the data notification receiver.

Parameters

content (str) – Text or tail content

startPrefixMapping(prefix, uri)[source]

Start element prefix-URI namespace mapping.

Parameters
  • prefix (str) – Namespace prefix

  • uri (Optional[str]) – Namespace uri

close()

Close document notification receiver.

The receiver will flush any previous active element and return the first item in the objects stack.

Return type

Any

data(data)

Data notification receiver.

The receiver will append the given data content in the current data frame either in the text position 0 or in the tail position 1 whether the element has ended or not.

Parameters

data (str) – Text or tail content

end(qname)

End element notification receiver.

The receiver will flush any previous active element and set the next element to be flushed.

Parameters

qname (str) – Qualified name

endDocument()

Receive notification of the end of a document.

The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.

endElement(name)

Signals the end of an element in non-namespace mode.

The name parameter contains the name of the element type, just as with the startElement event.

endPrefixMapping(prefix)

End the scope of a prefix-URI mapping.

See startPrefixMapping for details. This event will always occur after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.

flush()

Flush element notification receiver.

The receiver will check if there is an active element present, collect and join the data frames for text/tail content and notify the main parser to finish the binding process for the element.

ignorableWhitespace(whitespace)

Receive notification of ignorable whitespace in element content.

Validating Parsers must use this method to report each chunk of ignorable whitespace (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.

SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

merge_parent_namespaces(ns_map)

Merge and return the given prefix-URI map with the parent node.

Register new prefixes with the parser.

Parameters

ns_map (Dict) – Namespace prefix-URI map

Return type

Dict

processingInstruction(target, data)

Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser should never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

setDocumentLocator(locator)

Called by the parser to give the application a locator for locating the origin of document events.

SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the DocumentHandler interface.

The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application’s business rules). The information returned by the locator is probably not sufficient for use with a search engine.

Note that the locator will return correct information only during the invocation of the events in this interface. The application should not attempt to use it at any other time.

skippedEntity(name)

Receive notification of a skipped entity.

The Parser will invoke this method once for each entity skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities properties.

start(qname, attrs, ns_map)

Start element notification receiver.

The receiver will flush any previous active element, append a new data frame to collect data content for the next active element and notify the main parser to prepare for next binding instruction.

Parameters
  • qname (str) – Qualified name

  • attrs (Dict) – Attribute key-value map

  • ns_map (Dict) – Namespace prefix-URI map

startDocument()

Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).

startElement(name, attrs)

Signals the start of an element in non-namespace mode.

The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.