Skip to content

Instantly share code, notes, and snippets.

@andreivasiliu
Created December 18, 2023 21:09
Show Gist options
  • Save andreivasiliu/cde0a669d75bb2d80ae1f6acd92d5263 to your computer and use it in GitHub Desktop.
Save andreivasiliu/cde0a669d75bb2d80ae1f6acd92d5263 to your computer and use it in GitHub Desktop.
use xml_schema_derive::XmlSchema;
#[derive(Debug, XmlSchema)]
#[xml_schema(source = "test.xsd", target_prefix = "my_prefix")]
struct MySchema;
fn main() {
println!("Hello, world!");
}
[package]
name = "zxsd"
version = "0.1.0"
edition = "2021"
[dependencies]
xml-schema-derive = { git = "https://github.com/media-io/xml-schema" }
yaserde = { git = "https://github.com/media-io/yaserde" }
yaserde_derive = { git = "https://github.com/media-io/yaserde" }
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.example.com/books"
targetNamespace="http://www.example.com/books">
<xs:complexType name="BookDetails">
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="Author" type="xs:string"/>
<xs:element name="More" type="tns:MoreDetails"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MoreDetails">
<xs:sequence>
<xs:element name="Year" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<!-- Works! -->
<xs:element name="Book1" type="tns:BookDetails"/>
<!-- Crashes with:
cannot find type `BookDetails` in this scope
help: consider importing this struct: crate::types::BookDetails -->
<!-- New! with the new code, it now says:
use of undeclared crate or module `xml_schema_types`
consider importing this module through its public re-export: crate::xml_schema_types -->
<xs:element name="Book2">
<xs:complexType>
<xs:sequence>
<xs:element name="details" type="tns:BookDetails"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment