A while back I created this graphic to show the relationship between a document query and the document schema. If you’re new to AIF, this may help you understand the format of the data that flows in and out of AIF through the document services.
When using a document service in AIF, you call a service operation such as SalesOrder.read to read the sales order. When the service operation is called, the service passes this request to the Axd<Document> class, in this case AxdSalesOrder. The document class is based on a query, in this case the query is also called AxdSalesOrder. The query defines the schema for the document. So when the sales order data is sent from AX back to the calling system in XML, the structure of the XML matches that of the source query.
The attached image shows you the XML elements and how they map to the elements in the source query. The document itself is “SalesOrder” while each data source in the query has an “entity” attribute. (Normally, I would link to the graphic but I encountered what we like to call "challenges" when uploading the file.)
Hopefully this elucidates the XML document structure and will help you in troubleshooting.