QXmlContentHandlerclass provides an interface to report the logical content of XML data. 更多 …
继承者: QXmlDefaultHandler
If the application needs to be informed of basic parsing events, it can implement this interface and activate it using
setContentHandler(). The reader can then report basic document-related events like the start and end of elements and character data through this interface.The order of events in this interface is very important, and mirrors the order of information in the document itself. For example, all of an element’s content (character data, processing instructions, and sub-elements) appears, in order, between the
startElement()event and the correspondingendElement()事件。类
QXmlDefaultHandlerprovides a default implementation for this interface; subclassing from theQXmlDefaultHandlerclass is very convenient if you only want to be informed of some parsing events.
startDocument()function is called at the start of the document, andendDocument()is called at the end. Before parsing beginssetDocumentLocator()is called. For each elementstartElement()is called, withendElement()being called at the end of each element. Thecharacters()function is called with chunks of character data;ignorableWhitespace()is called with chunks of whitespace andprocessingInstruction()is called with processing instructions. If an entity is skippedskippedEntity()is called. At the beginning of prefix-URI scopesstartPrefixMapping()被调用。
QXmlContentHandler
¶
PySide2.QtXml.QXmlContentHandler.
characters
(
ch
)
¶
ch – unicode
bool
The reader calls this function when it has parsed a chunk of character data (either normal character data or character data inside a CDATA section; if you need to distinguish between those two types you must use
startCDATA()
and
endCDATA()
). The character data is reported in
ch
.
Some readers report whitespace in element content using the
ignorableWhitespace()
function rather than using this one.
A reader may report the character data of an element in more than one chunk; e.g. a reader might want to report “a<b” in three events (“a “, “<” and ” b”).
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
PySide2.QtXml.QXmlContentHandler.
endDocument
(
)
¶
bool
The reader calls this function after it has finished parsing. It is called just once, and is the last handler function called. It is called after the reader has read all input or has abandoned parsing because of a fatal error.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
另请参阅
PySide2.QtXml.QXmlContentHandler.
endElement
(
namespaceURI
,
localName
,
qName
)
¶
namespaceURI – unicode
localName – unicode
qName – unicode
bool
The reader calls this function when it has parsed an end element tag with the qualified name
qName
, the local name
localName
和名称空间 URI
namespaceURI
.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
PySide2.QtXml.QXmlContentHandler.
endPrefixMapping
(
prefix
)
¶
prefix – unicode
bool
The reader calls this function to signal the end of a prefix mapping for the prefix
prefix
.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
PySide2.QtXml.QXmlContentHandler.
errorString
(
)
¶
unicode
The reader calls this function to get an error string, e.g. if any of the handler functions returns
false
.
PySide2.QtXml.QXmlContentHandler.
ignorableWhitespace
(
ch
)
¶
ch – unicode
bool
Some readers may use this function to report each chunk of whitespace in element content. The whitespace is reported in
ch
.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
PySide2.QtXml.QXmlContentHandler.
processingInstruction
(
target
,
data
)
¶
target – unicode
data – unicode
bool
The reader calls this function when it has parsed a processing instruction.
target
is the target name of the processing instruction and
data
is the data in the processing instruction.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
PySide2.QtXml.QXmlContentHandler.
setDocumentLocator
(
locator
)
¶
locator
–
QXmlLocator
The reader calls this function before it starts parsing the document. The argument
locator
是指针指向
QXmlLocator
which allows the application to get the parsing position within the document.
Do not destroy the
locator
; it is destroyed when the reader is destroyed. (Do not use the
locator
after the reader is destroyed).
PySide2.QtXml.QXmlContentHandler.
skippedEntity
(
name
)
¶
name – unicode
bool
Some readers may skip entities if they have not seen the declarations (e.g. because they are in an external DTD). If they do so they report that they skipped the entity called
name
by calling this function.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
PySide2.QtXml.QXmlContentHandler.
startDocument
(
)
¶
bool
The reader calls this function when it starts parsing the document. The reader calls this function just once, after the call to
setDocumentLocator()
, and before any other functions in this class or in the
QXmlDTDHandler
class are called.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
另请参阅
PySide2.QtXml.QXmlContentHandler.
startElement
(
namespaceURI
,
localName
,
qName
,
atts
)
¶
namespaceURI – unicode
localName – unicode
qName – unicode
atts
–
QXmlAttributes
bool
The reader calls this function when it has parsed a start element tag.
There is a corresponding
endElement()
call when the corresponding end element tag is read. The and
endElement()
calls are always nested correctly. Empty element tags (e.g.
<x/>
) cause a call to be immediately followed by an
endElement()
调用。
The attribute list provided only contains attributes with explicit values. The attribute list contains attributes used for namespace declaration (i.e. attributes starting with xmlns) only if the namespace-prefix property of the reader is true.
自变量
namespaceURI
is the namespace URI, or an empty string if the element has no namespace URI or if no namespace processing is done.
localName
is the local name (without prefix), or an empty string if no namespace processing is done,
qName
is the qualified name (with prefix) and
atts
are the attributes attached to the element. If there are no attributes,
atts
is an empty attributes object.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.
PySide2.QtXml.QXmlContentHandler.
startPrefixMapping
(
prefix
,
uri
)
¶
prefix – unicode
uri – unicode
bool
The reader calls this function to signal the begin of a prefix-URI namespace mapping scope. This information is not necessary for normal namespace processing since the reader automatically replaces prefixes for element and attribute names.
Note that and
endPrefixMapping()
calls are not guaranteed to be properly nested relative to each other: all events occur before the corresponding
startElement()
event, and all
endPrefixMapping()
events occur after the corresponding
endElement()
event, but their order is not otherwise guaranteed.
自变量
prefix
is the namespace prefix being declared and the argument
uri
is the namespace URI the prefix is mapped to.
若此函数返回
false
the reader stops parsing and reports an error. The reader uses the function
errorString()
to get the error message.