{"id":16727682,"url":"https://github.com/poiscript/strong-xml","last_synced_at":"2025-03-17T01:31:35.546Z","repository":{"id":40287963,"uuid":"241849283","full_name":"PoiScript/strong-xml","owner":"PoiScript","description":"Strong typed xml, based on xmlparser.","archived":false,"fork":false,"pushed_at":"2022-05-16T21:10:24.000Z","size":176,"stargazers_count":33,"open_issues_count":14,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T16:19:20.527Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PoiScript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-20T09:56:20.000Z","updated_at":"2023-10-29T22:23:13.000Z","dependencies_parsed_at":"2022-07-08T22:45:13.774Z","dependency_job_id":null,"html_url":"https://github.com/PoiScript/strong-xml","commit_stats":null,"previous_names":["poiscript/xmlparser-derive"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PoiScript%2Fstrong-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PoiScript%2Fstrong-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PoiScript%2Fstrong-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PoiScript%2Fstrong-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PoiScript","download_url":"https://codeload.github.com/PoiScript/strong-xml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243836015,"owners_count":20355615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T23:06:36.860Z","updated_at":"2025-03-17T01:31:35.211Z","avatar_url":"https://github.com/PoiScript.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strong-xml\n\nStrong typed xml, based on xmlparser.\n\n[![Build Status](https://github.com/PoiScript/strong-xml/workflows/Test/badge.svg)](https://github.com/PoiScript/strong-xml/actions?query=workflow%3ATest)\n[![Crates.io](https://img.shields.io/crates/v/strong-xml.svg)](https://crates.io/crates/strong-xml)\n[![Document](https://docs.rs/strong-xml/badge.svg)](https://docs.rs/strong-xml)\n\n### Quick Start\n\n```toml\nstrong-xml = \"0.6\"\n```\n\n```rust\nuse std::borrow::Cow;\nuse strong_xml::{XmlRead, XmlWrite};\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent\u003c'a\u003e {\n    #[xml(attr = \"attr1\")]\n    attr1: Cow\u003c'a, str\u003e,\n    #[xml(attr = \"attr2\")]\n    attr2: Option\u003cCow\u003c'a, str\u003e\u003e,\n    #[xml(child = \"child\")]\n    child: Vec\u003cChild\u003c'a\u003e\u003e,\n}\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"child\")]\nstruct Child\u003c'a\u003e {\n    #[xml(text)]\n    text: Cow\u003c'a, str\u003e,\n}\n\nassert_eq!(\n    (Parent { attr1: \"val\".into(), attr2: None, child: vec![] }).to_string().unwrap(),\n    r#\"\u003cparent attr1=\"val\"/\u003e\"#\n);\n\nassert_eq!(\n    Parent::from_str(r#\"\u003cparent attr1=\"val\" attr2=\"val\"\u003e\u003cchild\u003e\u003c/child\u003e\u003c/parent\u003e\"#).unwrap(),\n    Parent { attr1: \"val\".into(), attr2: Some(\"val\".into()), child: vec![Child { text: \"\".into() }] }\n);\n```\n\n### Attributes\n\n#### `#[xml(tag = \"\")]`\n\nSpecifies the xml tag of a struct or an enum variant.\n\n```rust\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent {}\n\nassert_eq!(\n    (Parent {}).to_string().unwrap(),\n    r#\"\u003cparent/\u003e\"#\n);\n\nassert_eq!(\n    Parent::from_str(r#\"\u003cparent/\u003e\"#).unwrap(),\n    Parent {}\n);\n```\n\n```rust\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"tag1\")]\nstruct Tag1 {}\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"tag2\")]\nstruct Tag2 {}\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\nenum Tag {\n    #[xml(tag = \"tag1\")]\n    Tag1(Tag1),\n    #[xml(tag = \"tag2\")]\n    Tag2(Tag2),\n}\n\nassert_eq!(\n    (Tag::Tag1(Tag1 {})).to_string().unwrap(),\n    r#\"\u003ctag1/\u003e\"#\n);\n\nassert_eq!(\n    Tag::from_str(r#\"\u003ctag2\u003e\u003c/tag2\u003e\"#).unwrap(),\n    Tag::Tag2(Tag2 {})\n);\n```\n\n#### `#[xml(attr = \"\")]`\n\nSpecifies that a struct field is attribute. Support\n`Cow\u003cstr\u003e`, `Option\u003cCow\u003cstr\u003e\u003e`, `T` and `Option\u003cT\u003e`\nwhere `T: FromStr + Display`.\n\n```rust\nuse strong_xml::{XmlRead, XmlWrite};\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent {\n    #[xml(attr = \"attr\")]\n    attr: usize\n}\n\nassert_eq!(\n    (Parent { attr: 42 }).to_string().unwrap(),\n    r#\"\u003cparent attr=\"42\"/\u003e\"#\n);\n\nassert_eq!(\n    Parent::from_str(r#\"\u003cparent attr=\"48\"\u003e\u003c/parent\u003e\"#).unwrap(),\n    Parent { attr: 48 }\n);\n```\n\n#### `#[xml(child = \"\")]`\n\nSpecifies that a struct field is a child element. Support\n`T`, `Option\u003cT\u003e`, `Vec\u003cT\u003e` where `T: XmlRead + XmlWrite`.\n\n```rust\nuse strong_xml::{XmlRead, XmlWrite};\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"tag1\")]\nstruct Tag1 {}\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"tag2\")]\nstruct Tag2 {}\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"tag3\")]\nstruct Tag3 {}\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\nenum Tag12 {\n    #[xml(tag = \"tag1\")]\n    Tag1(Tag1),\n    #[xml(tag = \"tag2\")]\n    Tag2(Tag2),\n}\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent {\n    #[xml(child = \"tag3\")]\n    tag3: Vec\u003cTag3\u003e,\n    #[xml(child = \"tag1\", child = \"tag2\")]\n    tag12: Option\u003cTag12\u003e\n}\n\nassert_eq!(\n    (Parent { tag3: vec![Tag3 {}], tag12: None }).to_string().unwrap(),\n    r#\"\u003cparent\u003e\u003ctag3/\u003e\u003c/parent\u003e\"#\n);\n\nassert_eq!(\n    Parent::from_str(r#\"\u003cparent\u003e\u003ctag2\u003e\u003c/tag2\u003e\u003c/parent\u003e\"#).unwrap(),\n    Parent { tag3: vec![], tag12: Some(Tag12::Tag2(Tag2 {})) }\n);\n```\n\n#### `#[xml(text)]`\n\nSpecifies that a struct field is text content.\nSupport `Cow\u003cstr\u003e`, `Vec\u003cCow\u003cstr\u003e\u003e`, `Option\u003cCow\u003cstr\u003e\u003e`,\n`T`, `Vec\u003cT\u003e`, `Option\u003cT\u003e` where `T: FromStr + Display`.\n\n```rust\nuse std::borrow::Cow;\nuse strong_xml::{XmlRead, XmlWrite};\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent\u003c'a\u003e {\n    #[xml(text)]\n    content: Cow\u003c'a, str\u003e,\n}\n\nassert_eq!(\n    (Parent { content: \"content\".into() }).to_string().unwrap(),\n    r#\"\u003cparent\u003econtent\u003c/parent\u003e\"#\n);\n\nassert_eq!(\n    Parent::from_str(r#\"\u003cparent\u003e\u003c/parent\u003e\"#).unwrap(),\n    Parent { content: \"\".into() }\n);\n```\n\n#### `#[xml(flatten_text = \"\")]`\n\nSpecifies that a struct field is child text element.\nSupport `Cow\u003cstr\u003e`, `Vec\u003cCow\u003cstr\u003e\u003e`, `Option\u003cCow\u003cstr\u003e\u003e`,\n`T`, `Vec\u003cT\u003e`, `Option\u003cT\u003e` where `T: FromStr + Display`.\n\n```rust\nuse std::borrow::Cow;\nuse strong_xml::{XmlRead, XmlWrite};\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent\u003c'a\u003e {\n    #[xml(flatten_text = \"child\")]\n    content: Cow\u003c'a, str\u003e,\n}\n\nassert_eq!(\n    (Parent { content: \"content\".into() }).to_string().unwrap(),\n    r#\"\u003cparent\u003e\u003cchild\u003econtent\u003c/child\u003e\u003c/parent\u003e\"#\n);\n\nassert_eq!(\n    Parent::from_str(r#\"\u003cparent\u003e\u003cchild\u003e\u003c/child\u003e\u003c/parent\u003e\"#).unwrap(),\n    Parent { content: \"\".into() }\n);\n```\n\n#### `#[xml(cdata)]`\n\nSpecifies a CDATA text. Should be used together with `text` or `flatten_text`.\n\n\u003e `#[xml(cdata)]` only changes the behavior of writing,\n\u003e text field without `#[xml(cdata)]` can still works with cdata tag.\n\n```rust\nuse std::borrow::Cow;\nuse strong_xml::{XmlRead, XmlWrite};\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent\u003c'a\u003e {\n    #[xml(text, cdata)]\n    content: Cow\u003c'a, str\u003e,\n}\n\nassert_eq!(\n    (Parent { content: \"content\".into() }).to_string().unwrap(),\n    r#\"\u003cparent\u003e\u003c![CDATA[content]]\u003e\u003c/parent\u003e\"#\n);\n```\n\n```rust\nuse std::borrow::Cow;\nuse strong_xml::{XmlRead, XmlWrite};\n\n#[derive(XmlWrite, XmlRead, PartialEq, Debug)]\n#[xml(tag = \"parent\")]\nstruct Parent\u003c'a\u003e {\n    #[xml(flatten_text = \"code\", cdata)]\n    content: Cow\u003c'a, str\u003e,\n}\n\nassert_eq!(\n    (Parent { content: r#\"hello(\"deities!\");\"#.into() }).to_string().unwrap(),\n    r#\"\u003cparent\u003e\u003ccode\u003e\u003c![CDATA[hello(\"deities!\");]]\u003e\u003c/code\u003e\u003c/parent\u003e\"#\n);\n```\n\n#### `#[xml(default)]`\n\nUse `Default::default()` if the value is not present when reading.\n\n```rust\nuse std::borrow::Cow;\nuse strong_xml::XmlRead;\n\n#[derive(XmlRead, PartialEq, Debug)]\n#[xml(tag = \"root\")]\nstruct Root {\n    #[xml(default, attr = \"attr\")]\n    attr: bool,\n}\n\nassert_eq!(\n    Root::from_str(r#\"\u003croot/\u003e\"#).unwrap(),\n    Root { attr: false }\n);\n\nassert_eq!(\n    Root::from_str(r#\"\u003croot attr=\"1\"/\u003e\"#).unwrap(),\n    Root { attr: true }\n);\n```\n\n### License\n\nMIT\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoiscript%2Fstrong-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoiscript%2Fstrong-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoiscript%2Fstrong-xml/lists"}