Skip to main content

SerializeOptions

Struct SerializeOptions 

Source
pub struct SerializeOptions {
    pub write_xml_decl: bool,
    pub format: bool,
    pub indent: String,
    pub html_mode: bool,
    pub xhtml: bool,
    pub out_charset: OutputCharset,
}
Expand description

Options that control how a Document is serialized back to XML text.

§Example

use sup_xml_core::{parse_str, serialize_with, SerializeOptions, ParseOptions};

let doc = parse_str("<root><child/></root>", &ParseOptions::default()).unwrap();
let opts = SerializeOptions { format: true, ..SerializeOptions::default() };
println!("{}", serialize_with(&doc, &opts));

Fields§

§write_xml_decl: bool

Emit <?xml version="…" encoding="…"?> as the first line. Default: true. Has no effect when html_mode is on (HTML5 has no XML declaration).

§format: bool

Pretty-print with newlines and indentation. When false (the default), whitespace text nodes are preserved exactly as parsed. When true, whitespace-only text nodes between elements are dropped and fresh indentation is added. Default: false.

§indent: String

The string used for one indentation level when format is true. Default: two spaces (" ").

§html_mode: bool

Emit HTML5-style serialization rather than XML. Differences:

  • Void elements (<br>, <img>, <input>, …) emit with no end tag and no self-closing slash<br> not <br/>.
  • Raw-text elements (<script>, <style>) emit their text content verbatim — no entity escaping. This is required because the HTML5 tokenizer treats those tags’ contents as literal text up to the close tag.
  • Empty non-void elements emit as <div></div>, not <div/>. HTML5 doesn’t support self-closing on non-void elements; browsers parse <div/> as <div> with no close.
  • Boolean attributes use shorthand: <input disabled> instead of <input disabled=""> or <input disabled="disabled">. Detected when the attribute value is empty or matches the attribute name (case-insensitive) — these are spec-equivalent forms in HTML5.
  • The XML declaration is suppressed regardless of write_xml_decl.
  • If the document carries html_metadata with a captured DOCTYPE, that DOCTYPE is emitted as the first line. For documents without a stored DOCTYPE we don’t fabricate one — caller’s responsibility to insert <!DOCTYPE html> if they want it.

Default: false. Turn on when emitting output meant to be consumed by browsers / HTML parsers rather than XML parsers.

§xhtml: bool

Serialize per libxml2’s xhtmlNodeDumpOutput (XML syntax with XHTML accommodations), used when the document’s DOCTYPE identifies it as XHTML. Distinct from html_mode: output is still well-formed XML, but a root <html> carrying no namespace gains xmlns="http://www.w3.org/1999/xhtml", an empty non-void element is written <tag></tag> (browsers mis-parse <tag/>), and an empty void element (br, img, …) is written <tag />.

Default: false.

§out_charset: OutputCharset

The charset the output bytes will ultimately be encoded into. Characters it cannot represent are written as numeric character references in text / attribute content — matching libxml2, where a non-UTF-8 output encoding (or no encoding at all, which defaults to ASCII) escapes anything outside its repertoire. Default: OutputCharset::Utf8 (no extra escaping).

Trait Implementations§

Source§

impl Clone for SerializeOptions

Source§

fn clone(&self) -> SerializeOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SerializeOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SerializeOptions

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.