Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

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

Open
dtolnay opened this issue Jan 20, 2019 · 5 comments
Open

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

dtolnay opened this issue Jan 20, 2019 · 5 comments

Comments

@dtolnay
Copy link
Owner

dtolnay commented Jan 20, 2019

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

@RazrFalcon
Copy link

RazrFalcon commented Jan 22, 2019

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

@mathstuf
Copy link

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…

@chriskrycho
Copy link

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.

@ZigRazor
Copy link

ZigRazor commented Jul 9, 2021

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

@songww
Copy link

songww commented Aug 10, 2021

A simple implementation of this dtd-rs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants