Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
This repository was 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

Description

@dtolnay

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions