Skip to content

X0lotl/xml-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XML Parser

A command-line interface for parsing XML files. This tool allows you to parse XML files and display their content in a structured format.

Technical description

The XML Parser processes XML files by breaking them down into their constituent elements, attributes, and text content. The parsing process involves the following steps:

  1. Lexical Analysis: The parser reads the XML file and identifies the different tokens such as tags, attributes, and text.
  2. Syntax Analysis: The parser checks the structure of the XML file against the defined grammar rules to ensure it is well-formed.
  3. Semantic Analysis: The parser interprets the meaning of the elements and attributes, converting them into a structured format.

The results of the parsing are used to create a tree-like structure representing the XML document. This structure can be used for various purposes, such as data extraction, transformation, and validation.

Features

  • Parse XML files
  • Display help information
  • Display credits information

Features

  • Parse XML files
  • Display help information
  • Display credits information

Usage

Build the project

cargo build

Run the project

cargo run -- parse --file <path_to_xml_file>

Display help information

cargo run -- help

Display credits information

cargo run -- credits

Run tests

cargo test

Grammar rules

Define whitespace characters

WHITESPACE = _{ " " | "\t" | "\r" | "\n" }

Define the root XML rule

xml = { SOI ~ element ~ EOI }

Define an XML element, which consists of a start tag, zero or more nested elements or text, and an end tag

element = { start_tag ~ (element | text)* ~ end_tag }

Define a start tag, which includes a name and optional attributes

start_tag = { "<" ~ name ~ (WHITESPACE ~ attribute)* ~ WHITESPACE? ~ ">" }

Define an end tag, which includes a name

end_tag = { "</" ~ name ~ ">" }

Define an attribute, which consists of a name and a value

attribute = { name ~ "=" ~ "\"" ~ value ~ "\"" }

Define a name, which can include alphanumeric characters, hyphens, underscores, and colons

name = { (ASCII_ALPHANUMERIC | "-" | "_" | ":")+ }

Define a value, which can include any character except a double quote

value = { (!"\"" ~ ANY)* }

Define text, which can include any character except a less-than sign

text = { (!"<" ~ ANY)+ }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published