Skip to main content

detect_message_type

Function detect_message_type 

Source
pub fn detect_message_type(xml: &str) -> Result<MessageId, ParseError>
Expand description

Extract the ISO 20022 message type from the root element’s xmlns attribute.

Scans the raw XML for the first occurrence of an xmlns attribute (or xmlns= on the root element) whose value matches the ISO 20022 namespace pattern.

§Errors

Returns ParseError::InvalidEnvelope if no matching namespace is found or the namespace is malformed.

§Examples

let xml = r#"<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.13"><FIToFICstmrCdtTrf/></Document>"#;
let id = detect_message_type(xml).unwrap();
assert_eq!(id.family,  "pacs");
assert_eq!(id.msg_id,  "008");
assert_eq!(id.variant, "001");
assert_eq!(id.version, "13");