How imported XFDF file is saved in the PDF

I am trying to understand how XFDF file data is stored in a PDF when XFDF is merged with PDF document. Any pictorial representation or architecture diagram would help me better understand the relation between merged XFDF file and PDF document.

I already went through above shared link and there it is showing PDF and XFDF are stored in two different locations. But I am looking for when XFDF is merged directly into PDF document then how is it stored within the PDF? Is XFDF annotation data is stored like an attachment or as a metadata or any other way in the PDF? What is the relation between PDF and merged XFDF file?

First XFDF is the XML version of FDF, where FDF is a PDF file with no pages, just annotations and form field values. So the first thing that happens is the XFDF is converted to FDFDoc and the XFDF itself is dropped, then FDFDoc itself is merged into the PDFDoc object.

There are effectively two parts to XFDF/FDF, Annots and Form Field values.

For Form Field values, then the PDF is form field values are updated.

For Annotations they are added to the PDF.

Is XFDF annotation data is stored like an attachment or as a metadata or any other way in the PDF?

So no, all the XFDF data is merged “inline” into the PDF and the XFDF itself (the XML) is never actually seen by the PDF (since it went through FDF interface).

To learn more the PDF and XFDF are all public standards (pre-ISO specs that is), so all the info is available online.

Is there a reason you are asking about XFDF?
Are you hoping to retrieve the info out of the PDF? If so, why does that help you?

XFDF is mapped to PDF structures described in Section 12.5 in PDF Reference Manual (https://tinyurl.com/3v9yzx7k)