1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Reading a complete ISO 20022 *business message* (Business Application Header
//! + message Document) in one call, without the `model` feature.
use crate;
use crate;
use cratedetect;
use crateouter_element;
use crate;
/// A parsed business message: its optional header, the detected message type,
/// and extracted business metadata.
/// Read a business message (header + document) from XML.
///
/// ```
/// let xml = r#"
/// <Envelope>
/// <AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001.02">
/// <BizMsgIdr>B-1</BizMsgIdr><MsgDefIdr>pacs.008.001.08</MsgDefIdr>
/// </AppHdr>
/// <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
/// <FIToFICstmrCdtTrf><GrpHdr><MsgId>M-1</MsgId></GrpHdr></FIToFICstmrCdtTrf>
/// </Document>
/// </Envelope>"#;
/// let bm = rust_iso20022::read_business_message(xml);
/// assert_eq!(bm.id.unwrap().message_name(), "pacs.008.001.08");
/// assert_eq!(bm.header.unwrap().biz_msg_idr.as_deref(), Some("B-1"));
/// assert_eq!(bm.metadata.message_id.as_deref(), Some("M-1"));
/// ```
/// A typed business message: the (lightweight) header plus the typed `Document`.
///
/// `D` is a generated message type (with a `model-<area>` feature). The
/// `<Document>` is lifted out of the envelope and parsed on its own, so this
/// works whether the message is a bare `<Document>` or an `AppHdr`+`Document`
/// envelope.
/// Parse a typed [`Envelope`] from business-message XML.
///
/// ```
/// # #[cfg(feature = "model-pacs")] {
/// use rust_iso20022::generated::pacs::pacs_008_001_08::Document;
/// let xml = r#"<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08"></Document>"#;
/// let env: rust_iso20022::Envelope<Document> =
/// rust_iso20022::parse_envelope(xml).unwrap();
/// let _from = env.header.and_then(|h| h.from);
/// let _doc = env.document;
/// # }
/// ```