XmlParserCtxt

Struct XmlParserCtxt 

Source
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: u16

Implementations§

Source§

impl<'a> XmlParserCtxt<'a>

Source

pub fn new() -> Option<Self>

Allocate and initialize a new parser context.

Returns the xmlParserCtxtPtr or NULL

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn encoding(&self) -> Option<&str>

Source

pub fn input(&self) -> Option<&XmlParserInput<'_>>

Source

pub fn input_mut(&mut self) -> Option<&mut XmlParserInput<'a>>

Source

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.

Source

pub fn stop(&mut self)

Blocks further parser processing

Source

pub fn reset(&mut self)

Reset a parser context

Source

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

Source

pub fn clear(&mut self)

Clear (release owned resources) and reinitialize a parser context

Source

pub fn content_bytes(&self) -> &[u8]

Source

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

Source

pub fn input_pop(&mut self) -> Option<XmlParserInput<'a>>

Pops the top parser input from the input stack

Returns the input just removed

Source

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

Source

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

Source

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.

Source

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

Source

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<'_>

Source

pub fn parse_external_subset( &mut self, external_id: Option<&str>, system_id: Option<&str>, )

Parse Markup declarations from an external subset

[30] extSubset ::= textDecl? extSubsetDecl
[31] extSubsetDecl ::= (markupdecl | conditionalSect | PEReference | S) *
Source§

impl XmlParserCtxt<'_>

Source

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<'_>

Source

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? content

Returns 0 if the entity is well formed, -1 in case of args problem and the parser error code otherwise

Source

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? content

Returns 0, -1 in case of error. the parser context is augmented as a result of the parsing.

Source§

impl XmlParserCtxt<'_>

Source

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<'_>

Source

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

Source

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<'_>

Source

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

Source

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

Source

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

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl Default for XmlParserCtxt<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for XmlParserCtxt<'_>

Source§

fn drop(&mut self)

Free all the memory used by a parser context. However the parsed document in self.myDoc is not freed.

Auto Trait Implementations§

§

impl<'a> Freeze for XmlParserCtxt<'a>

§

impl<'a> !RefUnwindSafe for XmlParserCtxt<'a>

§

impl<'a> !Send for XmlParserCtxt<'a>

§

impl<'a> !Sync for XmlParserCtxt<'a>

§

impl<'a> Unpin for XmlParserCtxt<'a>

§

impl<'a> !UnwindSafe for XmlParserCtxt<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V