Bind Mapped XML Data (Custom XML Part) with Content Control containing Section Break in Word Document using C# or Java

@awais.hafeez @tahir.manzoor
Thanks for the update.

I need to bind the custom XML part with content controls, but if the section break present inside the content control, then I am not able to bind the custom XML part with StructuredDocumentTagRangeStart.

How to Bind the custom XML part with content controls, if the section break present inside the content control?


Please see these input and output Word DOCX documents and try running the following C# code of Aspose.Words for .NET API that will bind repeating section content control in Word document with custom XML:

Repeating Section Content Control sample DOCX (30.8 KB)

C# Code:

Document doc = new Document("C:\\Temp\\Repeating Section Content Control.docx");

Table table = doc.FirstSection.Body.Tables[0];

StructuredDocumentTag repeatingSection = (StructuredDocumentTag)table.GetChild(NodeType.StructuredDocumentTag, 0, false);
StructuredDocumentTag repeatingItem = (StructuredDocumentTag)repeatingSection.GetChild(NodeType.StructuredDocumentTag, 0, false);
Node[] repeatingSdts = repeatingItem.GetChildNodes(NodeType.StructuredDocumentTag, true).ToArray();

const string xml =
    @"<?xml version=""1.0"" encoding=""utf-8""?>
                <Name>John Doe</Name>
                <Name>Jane Adams</Name>
                <Name>John Smith</Name>

CustomXmlPart customXmlPart = doc.CustomXmlParts.Add(Guid.NewGuid().ToString("B"), xml);

repeatingSection.XmlMapping.SetMapping(customXmlPart, "/root/Employee", null);
((StructuredDocumentTag)repeatingSdts[0]).XmlMapping.SetMapping(customXmlPart, "/root/Employee/Name", null);
((StructuredDocumentTag)repeatingSdts[1]).XmlMapping.SetMapping(customXmlPart, "/root/Employee/HireDate", null);
((StructuredDocumentTag)repeatingSdts[2]).XmlMapping.SetMapping(customXmlPart, "/root/Employee/Gender", null);
((StructuredDocumentTag)repeatingSdts[3]).XmlMapping.SetMapping(customXmlPart, "/root/Employee/Department", null);


Hope, this helps in achieving what you are looking for.

The previous post related to CXP binding with StructuredDocumentTagRangeStart.

I have a very simple test, I am opening the document and iterate all the content controls and get mapped XML data. Unfortunately, I am not able to get mapped XML data (CustomXmlPart) from StructuredDocumentTagRangeStart. (17.9 KB)


We have logged this requirement in our issue tracking system. Your ticket number is WORDSNET-21062. We will further look into the details of this requirement and will keep you updated on the status of the linked issue.

A post was split to a new topic: Add more properties/methods in StructuredDocumentTagRangeStart Class

The issues you have found earlier (filed as WORDSNET-21062) have been fixed in this Aspose.Words for .NET 20.10 update and this Aspose.Words for Java 20.10 update.