Coder Social home page Coder Social logo

xml-serde's Introduction

Namespace aware XML (de)serializer for Rust utilizing Serde

// XML elements can be specified with structs
#[derive(Debug, Serialize, Deserialize)]
pub struct BulkObservable {
    // Required attributes can easily be defined, with the format of {namespace}ns-prefix:element
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:BulkObservableList")]
    pub list: String,

    // Repeated and optional elements can be defined with Vec and Option
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:AdditionalData", default, skip_serializing_if="Vec::is_empty")]
    pub additional_data: Vec<ExtensionType>,
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:BulkObservableFormat", default, skip_serializing_if="Option::is_none")]
    pub format: Option<BulkObservableFormat>,

    // Element attributes can be specified with the $attr: prefix
    #[serde(rename = "$attr:type")]
    pub bulk_type: BulkObservableType,
    #[serde(rename = "$attr:ext-type", default, skip_serializing_if="Option::is_none")]
    pub bulk_ext_type: Option<String>,

    // Textual element content can be set with the special name $value
    #[serde(rename = "$value")]
    pub value: f64,
}

// Enumerated values can also be defined
#[derive(Debug, Serialize, Deserialize)]
pub enum ConfidenceRating {
    #[serde(rename = "low")]
    Low,
    #[serde(rename = "medium")]
    Medium,
    #[serde(rename = "high")]
    High,
    #[serde(rename = "numeric")]
    Numeric,
    #[serde(rename = "unknown")]
    Unknown
}

// As can enumerated objects
#[derive(Debug, Serialize, Deserialize)]
pub enum IndicatorExpressionInner {
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}IndicatorExpression")]
    IndicatorExpression(IndicatorExpression),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}Observable")]
    Observable(Observable),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}ObservableReference")]
    ObservableReference(ObservableReference),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}IndicatorReference")]
    IndicatorReference(IndicatorReference),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}AdditionalData")]
    AdditionalData(ExtensionType),
}

xml-serde's People

Contributors

theenbyperor avatar willglynn avatar shadowjonathan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.