pub struct XmlParserCtxt<'a> {Show 16 fields
pub sax: Option<Box<XmlSAXHandler>>,
pub user_data: Option<GenericErrorContext>,
pub my_doc: Option<XmlDocPtr>,
pub well_formed: bool,
pub encoding: Option<String>,
pub input_tab: Vec<XmlParserInput<'a>>,
pub err_no: i32,
pub valid: i32,
pub vctxt: XmlValidCtxt,
pub instate: XmlParserInputState,
pub in_subset: i32,
pub charset: XmlCharEncoding,
pub last_error: XmlError,
pub sizeentities: u64,
pub sizeentcopy: u64,
pub nb_errors: u16,
/* private fields */
}Expand description
The parser context.
§Note
This doesn’t completely define the parser state, the (current ?) design of the parser uses recursive function calls since this allow and easy mapping from the production rules of the specification to the actual code. The drawback is that the actual function call also reflect the parser state. However most of the parsing routines takes as the only argument the parser context pointer, so migrating to a state based parser for progressive parsing shouldn’t be too hard.
Fields§
§sax: Option<Box<XmlSAXHandler>>§user_data: Option<GenericErrorContext>§my_doc: Option<XmlDocPtr>§well_formed: bool§encoding: Option<String>§input_tab: Vec<XmlParserInput<'a>>§err_no: i32§valid: i32§vctxt: XmlValidCtxt§instate: XmlParserInputState§in_subset: i32§charset: XmlCharEncoding§last_error: XmlError§sizeentities: u64§sizeentcopy: u64§nb_errors: u16Implementations§
Source§impl<'a> XmlParserCtxt<'a>
impl<'a> XmlParserCtxt<'a>
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Allocate and initialize a new parser context.
Returns the xmlParserCtxtPtr or NULL
Sourcepub fn new_sax_parser(
sax: Option<Box<XmlSAXHandler>>,
user_data: Option<GenericErrorContext>,
) -> Result<Self, Option<Box<XmlSAXHandler>>>
pub fn new_sax_parser( sax: Option<Box<XmlSAXHandler>>, user_data: Option<GenericErrorContext>, ) -> Result<Self, Option<Box<XmlSAXHandler>>>
Allocate and initialize a new SAX parser context.
If userData is NULL, the parser context will be passed as user data.
Returns the xmlParserCtxtPtr or NULL if memory allocation failed.
Sourcepub fn from_filename(filename: Option<&str>) -> Option<XmlParserCtxt<'_>>
pub fn from_filename(filename: Option<&str>) -> Option<XmlParserCtxt<'_>>
Create a parser context for a file content.
In original libxml2, automatic support for ZLIB/Compress compressed document is provided
by default if found at compile-time.
However, this crate does not support currently.
Returns the new parser context or NULL
Sourcepub fn from_filename_with_options(
filename: Option<&str>,
options: i32,
) -> Option<XmlParserCtxt<'_>>
pub fn from_filename_with_options( filename: Option<&str>, options: i32, ) -> Option<XmlParserCtxt<'_>>
Create a parser context for a file or URL content.
In original libxml2, automatic support for ZLIB/Compress compressed document is provided
by default if found at compile-time.
However, this crate does not support currently.
Returns the new parser context or NULL
Sourcepub fn from_io(
sax: Option<Box<XmlSAXHandler>>,
user_data: Option<GenericErrorContext>,
ioctx: impl Read + 'a,
enc: XmlCharEncoding,
) -> Option<Self>
pub fn from_io( sax: Option<Box<XmlSAXHandler>>, user_data: Option<GenericErrorContext>, ioctx: impl Read + 'a, enc: XmlCharEncoding, ) -> Option<Self>
Create a parser context for using the XML parser with an existing I/O stream
Returns the new parser context or NULL
Sourcepub fn from_memory(buffer: &'a [u8]) -> Option<Self>
pub fn from_memory(buffer: &'a [u8]) -> Option<Self>
Create a parser context for an XML in-memory document.
Returns the new parser context or NULL
Sourcepub fn new_entity_parser(
url: Option<&str>,
id: Option<&str>,
base: Option<&str>,
) -> Result<Self, Option<Box<XmlSAXHandler>>>
pub fn new_entity_parser( url: Option<&str>, id: Option<&str>, base: Option<&str>, ) -> Result<Self, Option<Box<XmlSAXHandler>>>
Create a parser context for an external entity
In original libxml2, automatic support for ZLIB/Compress compressed document is provided
by default if found at compile-time.
However, this crate does not support currently.
Returns the new parser context or NULL
pub fn encoding(&self) -> Option<&str>
pub fn input(&self) -> Option<&XmlParserInput<'_>>
pub fn input_mut(&mut self) -> Option<&mut XmlParserInput<'a>>
Sourcepub fn byte_consumed(&mut self) -> i64
pub fn byte_consumed(&mut self) -> i64
This function provides the current index of the parser relative to the start of the current entity. This function is computed in bytes from the beginning starting at zero and finishing at the size in byte of the file if parsing a file. The function is of constant cost if the input is UTF-8 but can be costly if run on non-UTF-8 input.
Returns the index in bytes from the beginning of the entity or -1 in case the index could not be computed.
Sourcepub fn reset_push(
&mut self,
chunk: &[u8],
filename: Option<&str>,
encoding: Option<&str>,
) -> i32
pub fn reset_push( &mut self, chunk: &[u8], filename: Option<&str>, encoding: Option<&str>, ) -> i32
Reset a push parser context
Returns 0 in case of success and 1 in case of error
pub fn content_bytes(&self) -> &[u8] ⓘ
Sourcepub fn input_push(&mut self, value: XmlParserInput<'a>) -> usize
pub fn input_push(&mut self, value: XmlParserInput<'a>) -> usize
Pushes a new parser input on top of the input stack
Returns -1 in case of error, the index in the stack otherwise
Sourcepub fn input_pop(&mut self) -> Option<XmlParserInput<'a>>
pub fn input_pop(&mut self) -> Option<XmlParserInput<'a>>
Pops the top parser input from the input stack
Returns the input just removed
Sourcepub fn push_input(
&mut self,
input: XmlParserInput<'a>,
) -> Result<usize, XmlParserErrors>
pub fn push_input( &mut self, input: XmlParserInput<'a>, ) -> Result<usize, XmlParserErrors>
Match to a new input stream which is stacked on top of the previous one(s).
Returns -1 in case of error or the index in the input stack
Sourcepub fn pop_input(&mut self) -> u8
pub fn pop_input(&mut self) -> u8
The current input pointed by self.input came to an end pop it and return the next c_char.
Returns the current XmlChar in the parser context
Sourcepub fn use_options(&mut self, options: i32) -> i32
pub fn use_options(&mut self, options: i32) -> i32
Applies the options to the parser context
Returns 0 in case of success, the set of unknown or unimplemented options in case of error.
Sourcepub fn switch_to_encoding(&mut self, handler: XmlCharEncodingHandler) -> i32
pub fn switch_to_encoding(&mut self, handler: XmlCharEncodingHandler) -> i32
change the input functions when discovering the character encoding of a given entity.
Returns 0 in case of success, -1 otherwise
Sourcepub fn switch_encoding(&mut self, enc: XmlCharEncoding) -> i32
pub fn switch_encoding(&mut self, enc: XmlCharEncoding) -> i32
Change the input functions when discovering the character encoding of a given entity.
Returns 0 in case of success, -1 otherwise
Source§impl XmlParserCtxt<'_>
impl XmlParserCtxt<'_>
Source§impl XmlParserCtxt<'_>
impl XmlParserCtxt<'_>
Sourcepub fn parse_content(&mut self)
pub fn parse_content(&mut self)
Parse a content sequence. Stops at EOF or ‘</’.
[43] content ::= (element | CharData | Reference | CDSect | PI | Comment)*Source§impl XmlParserCtxt<'_>
impl XmlParserCtxt<'_>
Sourcepub fn parse_external_entity(
&mut self,
url: Option<&str>,
id: Option<&str>,
lst: Option<&mut Option<XmlGenericNodePtr>>,
) -> i32
pub fn parse_external_entity( &mut self, url: Option<&str>, id: Option<&str>, lst: Option<&mut Option<XmlGenericNodePtr>>, ) -> i32
Parse an external general entity within an existing parsing context An external general parsed entity is well-formed if it matches the production labeled extParsedEnt.
[78] extParsedEnt ::= TextDecl? contentReturns 0 if the entity is well formed, -1 in case of args problem and the parser error code otherwise
Sourcepub fn parse_ext_parsed_ent(&mut self) -> i32
pub fn parse_ext_parsed_ent(&mut self) -> i32
parse a general parsed entity An external general parsed entity is well-formed if it matches the production labeled extParsedEnt.
[78] extParsedEnt ::= TextDecl? contentReturns 0, -1 in case of error. the parser context is augmented as a result of the parsing.
Source§impl XmlParserCtxt<'_>
impl XmlParserCtxt<'_>
Sourcepub fn parse_document(&mut self) -> i32
pub fn parse_document(&mut self) -> i32
Parse an XML document (and build a tree if using the standard SAX interface).
[1] document ::= prolog element Misc*
[22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?Returns 0, -1 in case of error. the parser context is augmented as a result of the parsing.
Source§impl XmlParserCtxt<'_>
impl XmlParserCtxt<'_>
Sourcepub fn new_push_parser(
sax: Option<Box<XmlSAXHandler>>,
user_data: Option<GenericErrorContext>,
chunk: &[u8],
filename: Option<&str>,
) -> Option<Self>
pub fn new_push_parser( sax: Option<Box<XmlSAXHandler>>, user_data: Option<GenericErrorContext>, chunk: &[u8], filename: Option<&str>, ) -> Option<Self>
Create a parser context for using the XML parser in push mode. If @buffer and @size are non-NULL, the data is used to detect the encoding. The remaining characters will be parsed so they don’t need to be fed in again through xmlParseChunk. To allow content encoding detection, @size should be >= 4 The value of @filename is used for fetching external entities and error/warning reports.
Returns the new parser context or NULL
Sourcepub unsafe fn parse_chunk(&mut self, chunk: &[u8], terminate: i32) -> i32
pub unsafe fn parse_chunk(&mut self, chunk: &[u8], terminate: i32) -> i32
Parse a Chunk of memory
Returns zero if no error, the xmlParserErrors otherwise.
Source§impl XmlParserCtxt<'_>
impl XmlParserCtxt<'_>
Sourcepub fn add_id(
&mut self,
doc: XmlDocPtr,
value: &str,
attr: XmlAttrPtr,
) -> Option<()>
pub fn add_id( &mut self, doc: XmlDocPtr, value: &str, attr: XmlAttrPtr, ) -> Option<()>
Register a new id declaration
Returns null_mut() if not, otherwise the new xmlIDPtr
Sourcepub fn add_element_decl(
&mut self,
dtd: Option<XmlDtdPtr>,
name: &str,
typ: Option<XmlElementTypeVal>,
content: Option<Rc<ElementContent>>,
) -> Option<XmlElementPtr>
pub fn add_element_decl( &mut self, dtd: Option<XmlDtdPtr>, name: &str, typ: Option<XmlElementTypeVal>, content: Option<Rc<ElementContent>>, ) -> Option<XmlElementPtr>
Register a new element declaration
Returns null_mut() if not, otherwise the entity
Sourcepub fn add_attribute_decl(
&mut self,
dtd: Option<XmlDtdPtr>,
elem: &str,
name: &str,
ns: Option<&str>,
typ: XmlAttributeType,
def: XmlAttributeDefault,
default_value: Option<&str>,
tree: Option<Box<XmlEnumeration>>,
) -> Option<XmlAttributePtr>
pub fn add_attribute_decl( &mut self, dtd: Option<XmlDtdPtr>, elem: &str, name: &str, ns: Option<&str>, typ: XmlAttributeType, def: XmlAttributeDefault, default_value: Option<&str>, tree: Option<Box<XmlEnumeration>>, ) -> Option<XmlAttributePtr>
Register a new attribute declaration Note that @tree becomes the ownership of the DTD
Returns null_mut() if not new, otherwise the attribute decl
Sourcepub fn normalize_attribute_value<'a>(
&mut self,
doc: XmlDocPtr,
elem: XmlNodePtr,
name: &str,
value: &'a str,
) -> Option<Cow<'a, str>>
pub fn normalize_attribute_value<'a>( &mut self, doc: XmlDocPtr, elem: XmlNodePtr, name: &str, value: &'a str, ) -> Option<Cow<'a, str>>
Does the validation related extra step of the normalization of attribute values:
If the declared value is not CDATA, then the XML processor must further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by single space (#x20) character.
Also check VC: Standalone Document Declaration in P32, and update (*ctxt).valid accordingly
Returns a new normalized string if normalization is needed, null_mut() otherwise the caller must free the returned value.
Sourcepub fn vpush_element(
&mut self,
doc: XmlDocPtr,
elem: XmlNodePtr,
qname: &str,
) -> i32
pub fn vpush_element( &mut self, doc: XmlDocPtr, elem: XmlNodePtr, qname: &str, ) -> i32
Push a new element start on the validation stack.
returns 1 if no validation problem was found or 0 otherwise
Sourcepub fn vpop_element(
&mut self,
_doc: Option<XmlDocPtr>,
_elem: Option<XmlNodePtr>,
_qname: &str,
) -> i32
pub fn vpop_element( &mut self, _doc: Option<XmlDocPtr>, _elem: Option<XmlNodePtr>, _qname: &str, ) -> i32
Pop the element end from the validation stack.
Returns 1 if no validation problem was found or 0 otherwise
Sourcepub fn vpush_cdata(&mut self, data: &str) -> i32
pub fn vpush_cdata(&mut self, data: &str) -> i32
Check the CData parsed for validation in the current stack
Returns 1 if no validation problem was found or 0 otherwise
Sourcepub fn build_content_model(&mut self, elem: XmlElementPtr) -> i32
pub fn build_content_model(&mut self, elem: XmlElementPtr) -> i32
(Re)Build the automata associated to the content model of this element
Returns 1 in case of success, 0 in case of error
Sourcepub fn validate_root(&mut self, doc: XmlDocPtr) -> i32
pub fn validate_root(&mut self, doc: XmlDocPtr) -> i32
Try to validate a the root element basically it does the following check as described by the XML-1.0 recommendation:
- [ VC: Root Element Type ] it doesn’t try to recurse or apply other check to the element
returns 1 if valid or 0 otherwise
Sourcepub fn validate_one_element(
&mut self,
doc: XmlDocPtr,
elem: Option<XmlGenericNodePtr>,
) -> i32
pub fn validate_one_element( &mut self, doc: XmlDocPtr, elem: Option<XmlGenericNodePtr>, ) -> i32
Try to validate a single element and it’s attributes, basically it does the following checks as described by the XML-1.0 recommendation:
- [ VC: Element Valid ]
- [ VC: Required Attribute ] Then call xmlValidateOneAttribute() for each attribute present.
The ID/IDREF checkings are done separately
returns 1 if valid or 0 otherwise
Sourcepub fn validate_element(
&mut self,
doc: XmlDocPtr,
root: Option<XmlGenericNodePtr>,
) -> i32
pub fn validate_element( &mut self, doc: XmlDocPtr, root: Option<XmlGenericNodePtr>, ) -> i32
Try to validate the subtree under an element
returns 1 if valid or 0 otherwise
Sourcepub fn validate_one_attribute(
&mut self,
doc: XmlDocPtr,
elem: XmlNodePtr,
attr: Option<XmlAttrPtr>,
value: &str,
) -> i32
pub fn validate_one_attribute( &mut self, doc: XmlDocPtr, elem: XmlNodePtr, attr: Option<XmlAttrPtr>, value: &str, ) -> i32
Try to validate a single attribute for an element basically it does the following checks as described by the XML-1.0 recommendation:
- [ VC: Attribute Value Type ]
- [ VC: Fixed Attribute Default ]
- [ VC: Entity Name ]
- [ VC: Name Token ]
- [ VC: ID ]
- [ VC: IDREF ]
- [ VC: Entity Name ]
- [ VC: Notation Attributes ]
The ID/IDREF uniqueness and matching are done separately
returns 1 if valid or 0 otherwise
Sourcepub fn validate_one_namespace(
&mut self,
doc: XmlDocPtr,
elem: XmlNodePtr,
prefix: Option<&str>,
ns: XmlNsPtr,
value: &str,
) -> i32
pub fn validate_one_namespace( &mut self, doc: XmlDocPtr, elem: XmlNodePtr, prefix: Option<&str>, ns: XmlNsPtr, value: &str, ) -> i32
Try to validate a single namespace declaration for an element basically it does the following checks as described by the XML-1.0 recommendation:
- [ VC: Attribute Value Type ]
- [ VC: Fixed Attribute Default ]
- [ VC: Entity Name ]
- [ VC: Name Token ]
- [ VC: ID ]
- [ VC: IDREF ]
- [ VC: Entity Name ]
- [ VC: Notation Attributes ]
The ID/IDREF uniqueness and matching are done separately
returns 1 if valid or 0 otherwise
Sourcepub fn validate_dtd_final(&mut self, doc: XmlDocPtr) -> i32
pub fn validate_dtd_final(&mut self, doc: XmlDocPtr) -> i32
Does the final step for the dtds validation once all the subsets have been parsed
basically it does the following checks described by the XML Rec
- check that ENTITY and ENTITIES type attributes default or possible values matches one of the defined entities.
- check that NOTATION type attributes default or possible values matches one of the defined notations.
Returns 1 if valid or 0 if invalid and -1 if not well-formed
Sourcepub fn validate_element_decl(
&mut self,
doc: XmlDocPtr,
elem: Option<XmlElementPtr>,
) -> i32
pub fn validate_element_decl( &mut self, doc: XmlDocPtr, elem: Option<XmlElementPtr>, ) -> i32
Try to validate a single element definition basically it does the following checks as described by the XML-1.0 recommendation:
- [ VC: One ID per Element Type ]
- [ VC: No Duplicate Types ]
- [ VC: Unique Element Type Declaration ]
returns 1 if valid or 0 otherwise
Sourcepub fn validate_attribute_decl(
&mut self,
doc: XmlDocPtr,
attr: XmlAttributePtr,
) -> i32
pub fn validate_attribute_decl( &mut self, doc: XmlDocPtr, attr: XmlAttributePtr, ) -> i32
Try to validate a single attribute definition basically it does the following checks as described by the XML-1.0 recommendation:
- [ VC: Attribute Default Legal ]
- [ VC: Enumeration ]
- [ VC: ID Attribute Default ]
The ID/IDREF uniqueness and matching are done separately
returns 1 if valid or 0 otherwise
Sourcepub fn validate_notation_use(
&mut self,
doc: XmlDocPtr,
notation_name: &str,
) -> i32
pub fn validate_notation_use( &mut self, doc: XmlDocPtr, notation_name: &str, ) -> i32
Validate that the given name match a notation declaration.
- [ VC: Notation Declared ]
returns 1 if valid or 0 otherwise