dtolnay / request-for-implementation

Crates that don't exist, but should

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A dtd macro to generate struct definitions from an XML DTD file

dtolnay opened this issue · comments

I would like to be able to write:

dtd!("path/to/note.dtd");

or possibly inline:

dtd! {
    <!ELEMENT note (to,from,heading,body)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT heading (#PCDATA)>
    <!ELEMENT body (#PCDATA)>
}

and have this expand to the right data structures to represent data of this form. In this case simply:

// generated code
struct Note {
    to: String,
    from: String,
    heading: String,
    body: String,
}

Then also generate a parser using any one of the XML libraries listed here to deserialize the data structure from XML. Possibly like:

// generated code
impl Note {
    fn from_xml(document: &str) -> Result<Note, roxmltree::Error> {
        let tree = roxmltree::Document::parse(&document)?;

        /* ... */
    }
}

DTD references:
https://en.wikipedia.org/wiki/Document_type_definition
https://www.w3schools.com/xml/xml_dtd_intro.asp

AFAIK, only xmlparser does support DTD, but only ENTITY. I can add other objects if someone wants to implement this.

I think following the pattern used in the graphql-client would be great for this. Not so sure about the inline stuff. That'd be a very hairy macro implementation…

Yes, please!

I can’t make any promises, but it’s just possible I’ll have some cycles I could devote to some of this (testing and whatnot if nothing else!) starting in the next few weeks.

I will implement this feature soon in my repo. Follow and watch for update.

A simple implementation of this dtd-rs