> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/get-started/faq/extract-xml-from-xfa.md).

# How to extract XML from a XFA PDF form?

World's #1 PDF SDK Library for Web, Mobile, Server, Desktop

Suppose the XML data you want to extract is held inside the XFA Array, within the AcroForm dictionary. In order to extract all of the XFA data, you will need to iterate through this Array, and extract all of the content streams.

The following example shows how to extract the XML data at one specific index in the Array:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
// Example code for extracting an xml string from the XFA form,
// and putting it back after an update.

PDFDoc doc = new PDFDoc(filename); 

//get the acroform dictionary
Obj acro_form = doc.GetAcroForm(); 

// This PDF document contains XFA forms... 
Obj obj = acro_form.FindObj("XFA"); 

//We will store the XML string in this byte array
byte[] buff = new byte[4000];
byte byteRawPre, byteDecodePre, byteRawPost, byteDecodePost; 

pdftron.Filters.Filter filter; 
pdftron.Filters.FilterReader fr; 

//The XFA entry in the PDF is an Array, so in this case,
//we want to read the xml string stored at the 5th index of the Array
filter = obj.GetAt(5).GetDecodedStream(); 
fr = new pdftron.Filters.FilterReader(filter); 
fr.Read(buff); 
//at this point, the xml string should be stored inside buff,
//and you can make whatever modifications you want

//Modify XML String HERE

//We create an indirect stream object, which will contain our 
// newly modified XML string
Obj new_xmp_stm = doc.CreateIndirectStream(buff);

//The swap method allows us to switch all indirect references to the old stream,
// to point to our newly created stream.
doc.GetSDFDoc().Swap(
    new_xmp_stm.GetObjNum(), 
    acro_form.Get("XFA").Value().GetAt(5).GetObjNum()
); 

doc.Save(output_filename, SDFDoc.SaveOptions.e_linearized); 
doc.Close();
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/android/get-started/faq/extract-xml-from-xfa.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
