We are advised to migrate our legacy code from OpenXML to Aspose.Words, but after reviewing the product, i see the customXMLPart is not 100% compatible with OpenXML.
I have this working OpenXML code, and needed to be migrated to Aspose.Words,
OpenXML code generates a document that i can see the xml content is inserted inside the document. but using Aspose.Words, i do not see the xml content is inside the document.
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(templateFile, true))
{ wordDoc.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
mainPart.DeleteParts<CustomXmlPart>(mainPart.CustomXmlParts);
// Add a new customXML part and then add content
CustomXmlPart customXmlPart = mainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
// Copy the XML into the new part
using (StreamWriter ts = new StreamWriter(customXmlPart.GetStream()))
ts.Write(customXML);
mainPart.Document.Save();
}
here the Aspose.Words code ->
var myxmlPart = new Aspose.Words.Markup.CustomXmlPart();
string sXML = customXML.ToString();
myxmlPart.Data = System.Text.Encoding.ASCII.GetBytes(sXML);
myxmlPart.Id = Guid.NewGuid().ToString().ToUpper();
// xpc.Clear();
doc.CustomXmlParts.Add(myxmlPart);
Aspose.Words.Markup.StructuredDocumentTag tag = new Aspose.Words.Markup.StructuredDocumentTag(doc, Aspose.Words.Markup.SdtType.PlainText,
Aspose.Words.Markup.MarkupLevel.Block);
//tag.XmlMapping.SetMapping(myxmlPart,"/root",string.Empty);
// doc.FirstSection.Body.AppendChild(tag);
string sfile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(templateFile), "11111.docx");
doc.Save(sfile);