8000 GitHub - tarunps/dtd-rs: A DTD parser implemented by rust.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tarunps/dtd-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DTD Parser

github crates.io docs.rs build status

Install

cargo add dtd-rs

Usage

use dtd::dtd;

// parse dtd elements.
dtd! {
    "<!ELEMENT note (to,from,heading,body)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT heading (#PCDATA)>
    <!ELEMENT body (#PCDATA)>"
};

// Generated:
//    pub struct Body(pub String);
//    #[derive(Clone, Debug)]
//    pub struct Body(pub String);
//    #[derive(Clone, Debug)]
//    pub struct Heading(pub String);
//    #[derive(Clone, Debug)]
//    pub struct From(pub String);
//    #[derive(Clone, Debug)]
//    pub struct To(pub String);
//    #[derive(Clone, Debug)]
//    pub struct TupleToFromHeadingBody {
//        pub to: To,
//        pub from: From,
//        pub heading: Heading,
//        pub body: Body,
//    }
//    pub type Note = TupleToFromHeadingBody;


let xml = r#"
<note>
  <to>You</to>
  <from>Me</from>
  <heading>Hello Friend</heading>
  <body>Hello You</body>
</note>
"#;
let note: Note = serde_xml_rs::from_str(xml);

println!("{:?}", note);

// Or parse from file:
//
// content of `path/to/file.dtd`
//    <!ELEMENT note (to,from,heading,body)>
//    <!ELEMENT to (#PCDATA)>
//    <!ELEMENT from (#PCDATA)>
//    <!ELEMENT heading (#PCDATA)>
//    <!ELEMENT body (#PCDATA)>
// parse from file
dtd!("path/to/file.dtd");

About

A DTD parser implemented by rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%
0