#![allow(dead_code)] use raxb::{value::ConstStr, XmlDeserialize, XmlSerialize}; #[derive(Debug, XmlDeserialize, XmlSerialize)] #[xml(root = b"Envelope")] #[xml(tns(b"SOAP", b"https://schemas.xmlsoap.org/soap/envelope/"))] pub struct Envelope where T: raxb::de::XmlDeserialize + raxb::ser::XmlSerialize + std::fmt::Debug, { #[xml( default, ns = b"xmlns", name = b"SOAP", ty = "attr", value = "https://schemas.xmlsoap.org/soap/envelope/" )] _xmlns: ConstStr, #[xml(ns = b"SOAP", name = b"Header", ty = "sfc")] pub header: bool, #[xml(ns = b"SOAP", name = b"Body", ty = "child")] pub body: T, } #[derive(Debug, XmlDeserialize, XmlSerialize)] pub struct Header { #[xml(ty = "text")] pub content: String, } #[derive(Debug, XmlDeserialize, XmlSerialize)] #[xml(tns(b"ex", b"https://my.example.org/"))] pub struct Example { #[xml( default, ns = b"xmlns", name = b"ex", ty = "attr", value = "https://my.example.org/" )] _xmlns: ConstStr, #[xml(ns = b"ex", name = b"header", ty = "child")] pub header: Header, } #[test] fn test_serialize_ns_derive() -> anyhow::Result<()> { let xml = raxb::ser::to_string(&Envelope:: { header: true, body: Example { header: Header { content: "BASE_64_ENCODED_XML".to_string(), }, _xmlns: Default::default(), }, _xmlns: Default::default(), })?; assert_eq!( xml, r#"BASE_64_ENCODED_XML"# ); Ok(()) } #[test] fn test_deserialize_ns_with_derive_macro() -> anyhow::Result<()> { let xml = r#" BASE_64_ENCODED_XML "#; let envelope: Envelope = raxb::de::from_str(xml)?; eprintln!("{envelope:#?}"); Ok(()) } #[derive(Debug, XmlDeserialize)] pub struct XsdImportOrInclude { #[xml(name = b"schemaLocation", ty = "attr")] pub schema_location: String, } #[derive(Debug, XmlDeserialize)] #[xml(root = b"schema")] #[xml(tns(b"xs", b"http://www.w3.org/2001/XMLSchema"))] pub struct Xsd { #[xml(ns = b"xs", name = b"include", ty = "sfc")] pub includes: Vec, #[xml(ns = b"xs", name = b"import", ty = "sfc")] pub imports: Vec, } #[test] fn test_deserialize_ns_with_derive_macro_with_decl() -> anyhow::Result<()> { let xml = r#" "#; let xsd: Xsd = raxb::de::from_str(xml)?; eprintln!("{xsd:#?}"); Ok(()) } #[test] fn test_deserialize_real_schema() -> anyhow::Result<()> { let xml = r#" "#; let xsd: Xsd = raxb::de::from_str(xml)?; eprintln!("{xsd:#?}"); Ok(()) }