| Crates.io | xml_language_tag_parser |
| lib.rs | xml_language_tag_parser |
| version | 0.1.4 |
| created_at | 2024-11-07 02:07:45.493059+00 |
| updated_at | 2024-11-17 02:32:43.352137+00 |
| description | A simple XML language tag parser |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1439383 |
| size | 30,680 |
The XML Language Tag Parser is a Rust-based parser designed to handle and parse XML documents with specific focus on extracting language tags, elements, attributes, and content. This parser is intended to facilitate processing XML documents in applications where structured content needs to be validated and manipulated. The parsed structure includes elements, attributes, and content, allowing for further use in applications that require such data in a structured format.
The parsing process involves using the pest library to define grammar rules for XML-like tags. These grammar rules are as follows:
pest parser library. It begins by breaking the document into tokens, which are then matched against predefined grammar rules.<div>, <p>) is identified. The parser extracts its tag name and attributes.id="123").open_tag), content (content), and a closing tag (close_tag).open_tag starts with a <, followed by a tag_name (the name of the element), optional attributes (if any), and ends with a >.close_tag starts with </, followed by a tag_name, and ends with a >./>.-), or underscores (_).=), and a value enclosed in double quotes.-), underscores (_), or colons (:).").content rule defines what can appear inside an element. It can be a mixture of other elements and text.< and >.For the input:
cargo run "<person id=\"1\" age=\"30\"><name>John Doe</name></person>"
Parsed XML Structure:
Element {
tag_name: "person",
attributes: [
Attribute {
name: "id",
value: "1",
},
Attribute {
name: "age",
value: "30",
},
],
content: [
Element {
tag_name: "name",
attributes: [],
content: [],
text: Some(
"John Doe",
),
},
],
text: None,
}