pub struct Config {
    pub leading_zero_as_string: bool,
    pub xml_attr_prefix: String,
    pub xml_text_node_prop_name: String,
    pub empty_element_handling: NullValue,
}
Expand description

Tells the converter how to perform certain conversions. See docs for individual fields for more info.

Fields§

§leading_zero_as_string: bool

Numeric values starting with 0 will be treated as strings. E.g. convert <agent>007</agent> into "agent":"007" or "agent":7 Defaults to false.

§xml_attr_prefix: String

Prefix XML attribute names with this value to distinguish them from XML elements. E.g. set it to @ for <x a="Hello!" /> to become {"x": {"@a":"Hello!"}} or set it to a blank string for {"x": {"a":"Hello!"}} Defaults to @.

§xml_text_node_prop_name: String

A property name for XML text nodes. E.g. set it to text for <x a="Hello!">Goodbye!</x> to become {"x": {"@a":"Hello!", "text":"Goodbye!"}} XML nodes with text only and no attributes or no child elements are converted into JSON properties with the name of the element. E.g. <x>Goodbye!</x> becomes {"x":"Goodbye!"} Defaults to #text

§empty_element_handling: NullValue

Defines how empty elements like <x /> should be handled.

Implementations§

source§

impl Config

source

pub fn new_with_defaults() -> Self

Numbers with leading zero will be treated as numbers. Prefix XML Attribute names with @ Name XML text nodes #text for XML Elements with other children

Examples found in repository?
examples/basic.rs (line 6)
4
5
6
7
8
9
10
11
12
13
fn main() {
    let xml = r#"<?xml version="1.0" encoding="utf-8"?><a attr1="1"><b><c attr2="001">some text</c></b></a>"#;
    let conf = Config::new_with_defaults();
    let json = xml_string_to_json(xml.to_owned(), &conf);
    println!("{}", json.expect("Malformed XML").to_string());

    let conf = Config::new_with_custom_values(true, "", "txt", NullValue::Null);
    let json = xml_string_to_json(xml.to_owned(), &conf);
    println!("{}", json.expect("Malformed XML").to_string());
}
source

pub fn new_with_custom_values( leading_zero_as_string: bool, xml_attr_prefix: &str, xml_text_node_prop_name: &str, empty_element_handling: NullValue ) -> Self

Create a Config object with non-default values. See the Config struct docs for more info.

Examples found in repository?
examples/basic.rs (line 10)
4
5
6
7
8
9
10
11
12
13
fn main() {
    let xml = r#"<?xml version="1.0" encoding="utf-8"?><a attr1="1"><b><c attr2="001">some text</c></b></a>"#;
    let conf = Config::new_with_defaults();
    let json = xml_string_to_json(xml.to_owned(), &conf);
    println!("{}", json.expect("Malformed XML").to_string());

    let conf = Config::new_with_custom_values(true, "", "txt", NullValue::Null);
    let json = xml_string_to_json(xml.to_owned(), &conf);
    println!("{}", json.expect("Malformed XML").to_string());
}

Trait Implementations§

source§

impl Debug for Config

source§

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

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

impl Default for Config

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> 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>,

§

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>,

§

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.