Crates.io | parse-sap-atom-feed |
lib.rs | parse-sap-atom-feed |
version | 0.2.8 |
source | src |
created_at | 2023-09-04 16:01:50.276223 |
updated_at | 2024-06-27 16:05:55.337158 |
description | Parse an SAP OData V2 XML atom:Feed |
homepage | |
repository | https://github.com/ChrisWhealy/parse-sap-atom-feed |
max_upload_size | |
id | 963329 |
size | 61,982 |
atom:Feed
This is a work in progress!
The crate is designed to work in conjunction with the source code generated from the
crate parse-sap-odata
.
Crate parse-sap-odata
is invoked by a Rust build script to parse an OData XML metadata file and generates the
Rust struct
s and enum
s needed to consume the entity set data described by that metadata.
This crate parse-sap-atom-feed
then makes use of the struct
s and enum
s generated above and allows your business
app to consume the XML returned when requesting entity sets from this OData service.
The main change in version 0.2 is to adopt quick-xml
'
s @
-prefixed attribute syntax
introduced in 0.27
and higher.
You want to develop a Rust application that can consume the entity set data exposed by an SAP OData V2 service.
For the purposes of instruction, let's say you're working with a custom OData service that displays services ordered either by functional location or by date:
Rust Application | zcustom-service-orders |
OData Service URL | https://my-sap-server.my-domain.com/sap/opu/odata/sap |
OData Service Name | ZCUSTOM_SERVICE_ORDERS_SRV |
OData Schema Name | ZCUSTOM_SERVICE_ORDERS |
Entity Names | SERVICE_ORDERS_BY_FLOC SERVICE_ORDERS_BY_DATE |
Entity Type | ZServiceOrder |
The general approach to consuming such a service is as follows:
cargo new zcustom-service-orders
cd zcustom-service-orders
Cargo.toml
to include at least the following dependencies
[build-dependencies]
parse-sap-odata = "1.1"
[dependencies]
chrono = { version = "0.4", features = ["serde"]}
parse-sap-atom-feed = "0.2"
quick-xml = { version = "0.32", features = ["serialize"] }
rust_decimal = { version = "1", features = ["serde-with-str"]}
serde = { version = "1.0", features = ["derive"] }
uuid = { version = "1.4", features = ["serde"]}
mkdir odata
https://my-sap-server.my-domain.com/sap/opu/odata/sap/ZCUSTOM_SERVICE_ORDERS_SRV/$metadata
zcustom_service_orders.xml
in the odata
directorybuild.rs
file in same directory as Cargo.toml
and add at least the following:
use parse_sap_odata::parser::gen_src;
fn main() {
gen_src("zcustom_service_orders", "ZCUSTOM_SERVICE_ORDERS");
}
src/main.rs
include at least:
use parse_sap_atom_feed::{
Feed,
xml::sanitise_xml,
str::{self, FromStr},
};
include!(concat!(env!("OUT_DIR"), "/zcustom_service_orders.rs"));
use zcustom_service_orders::*;
fn main() {
let raw_xml: String = /* Whatever code is needed to fetch the entity set data as a raw XML string */;
// You might need to sanitise the raw XML string before attempting to parse it
let clean_xml = sanitise_xml(raw_xml);
let srv_orders_by_floc = Feed::<ZServiceOrder>::from_str(&clean_xml);
}
Version | Description |
---|---|
0.2.8 | Implement std::str::FromStr for Atom types |
0.2.7 | Parse an Atom feed of <entry> elements |
0.2.6 | As per https://validator.w3.org/feed/docs/atom.html#requiredEntryElements, the Atom <content> element should either contain or link to, the complete content of the entry.If the src attribute is present, then the <properties> element (if present) exists as a sibling of the <content> element.If the src attribute is missing, the <properties> element must exist as a child of the <content> element.Add support for out-of-order XML elements (quick-xml feature overlapped-lists ) |
0.2.5 | Read generic OData service document |
0.2.4 | Update Cargo.toml dependency versions |