# XML Parser

**API Group:** `xmlsec_core_parser`

XML parsing helper functions.

XML parser functions and the XML parser transform implementation.

## Macros

### `xmlSecTransformXmlParserId`

*Defined as:* `xmlSecTransformXmlParserGetKlass()`

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L40)

The XML Parser transform klass.

---

## Functions

### `xmlSecParseFile`

```c
xmlDocPtr xmlSecParseFile(const char *filename);
```

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L21)

Loads an XML document from a file.

Loads XML Doc from file `filename`. We need a special version because of c14n issue. The code is copied from xmlSAXParseFileWithData() function. 

**Parameters:**

- `filename` — the filename.


**Returns:** pointer to the loaded XML document or NULL if an error occurs.

---

### `xmlSecParseMemory`

```c
xmlDocPtr xmlSecParseMemory(const xmlSecByte *buffer, xmlSecSize size, int recovery);
```

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L22)

Loads an XML document from memory.

Loads XML Doc from memory. We need a special version because of c14n issue. The code is copied from xmlSAXParseMemory() function. 

**Parameters:**

- `buffer` — the input buffer.
- `size` — the input buffer size.
- `recovery` — the flag.


**Returns:** pointer to the loaded XML document or NULL if an error occurs.

---

### `xmlSecParseMemoryExt`

```c
xmlDocPtr xmlSecParseMemoryExt(const xmlSecByte *prefix, xmlSecSize prefixSize, const xmlSecByte *buffer, xmlSecSize bufferSize, const xmlSecByte *postfix, xmlSecSize postfixSize);
```

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L25)

Loads an XML document from 3 memory chunks.

Loads XML Doc from 3 chunks of memory: `prefix`, `buffer` and `postfix`. 

**Parameters:**

- `prefix` — the first part of the input.
- `prefixSize` — the size of the first part of the input.
- `buffer` — the second part of the input.
- `bufferSize` — the size of the second part of the input.
- `postfix` — the third part of the input.
- `postfixSize` — the size of the third part of the input.


**Returns:** pointer to the loaded XML document or NULL if an error occurs.

---

### `xmlSecParsePrepareCtxt`

```c
void xmlSecParsePrepareCtxt(xmlParserCtxtPtr ctxt);
```

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L31)

Prepares parser context for XML parsing.

Prepares parser context for parsing XML for XMLSec. 

**Parameters:**

- `ctxt` — the parser context

---

### `xmlSecParserGetDefaultOptions`

```c
int xmlSecParserGetDefaultOptions(void);
```

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L33)

Gets default LibXML2 parser options.

**Returns:** the current default LibXML2 parser options.

---

### `xmlSecParserSetDefaultOptions`

```c
void xmlSecParserSetDefaultOptions(int options);
```

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L34)

Sets default LibXML2 parser options.

**Parameters:**

- `options` — the new parser options.

---

### `xmlSecTransformXmlParserGetKlass`

```c
xmlSecTransformId xmlSecTransformXmlParserGetKlass(void);
```

*Source:* [include/xmlsec/parser.h](https://github.com/lsh123/xmlsec/blob/1.3.12/include/xmlsec/parser.h#L42)

The XML parser transform.

**Returns:** XML parser transform klass.

---
