# XML import and export

Three XML shapes are supported.

## Structured (`ToXml` / `GetMessageAsXml`)

Named after the typed object model. Sequences and tags become XML elements such as `SendersReference_20`.

```csharp
string xml = message.ToXml();
string same = parser.GetMessageAsXml(message);
string same2 = message.ToXml(SwiftMessageExportType.Structured);
```

Requires the message to match its type definition. Otherwise `InvalidOperationException` is thrown.

Round-trip:

```csharp
string xml = message.ToXml();
SwiftMessage restored = parser.GetMessageFromXml(xml);
string fin = parser.GetMessageAsText(restored);
```

Root element example for MT103:

```xml
<ns0:SWIFT_CATEGORY1_MT103_Interchange xmlns:ns0="http://swiftcomponents.com/Category1/MT103">
  <SWIFTHeader>…</SWIFTHeader>
  <SWIFT_CATEGORY1_MT103>
    <SendersReference_20>ABCDEREF</SendersReference_20>
    …
  </SWIFT_CATEGORY1_MT103>
</ns0:SWIFT_CATEGORY1_MT103_Interchange>
```

## Raw (`ToXmlRaw` / `GetMessageAsXmlRaw`)

Serializes blocks and SWIFT tags only. Ignores the typed model, so invalid or unknown structures can still be exported.

```csharp
string raw = message.ToXmlRaw();
string same = parser.GetMessageAsXmlRaw(message);
string same2 = message.ToXml(SwiftMessageExportType.Raw);
```

## BizTalk

```csharp
string biztalk = message.ToXml(SwiftMessageExportType.Biztalk);
```

Use this when integrating with Microsoft BizTalk SWIFT schemas.

## Import

```csharp
SwiftMessage message = parser.GetMessageFromXml(xml);
```

Accepts structured and raw XML produced by this library.

## Enum

```csharp
public enum SwiftMessageExportType
{
    Structured,
    Raw,
    Biztalk
}
```
