Free Support Forum - aspose.com

XML Parser or Regex

Hello there,

I have some word templates(dot/dotx) files that contain xml tags along with plain text.
At run time, I need to replace the xml tags with their respective mail merge fields. I am using Aspose to run mail merge for all my documents.

So, need to parse the document for these xml tags and replace them with merge fields. I was using Regex to find and replace these xml tags. But I was suggested to use XML parser to parse for XML tags. The sample document is attached.

One more note, the angle brackets are typed manually by end user in the template, so not sure if the XML processor will understand them as XML tags or not.

I tried using XMLReader, but got error as my documents have no root tags on their own. Then I tried inserting start and end tag for root node myself at run-time, but still got the same error.

Please guide if I should stick to Regex or is there any way to use XML Parser for these tags.

Thank you!

        </div>

Hi Nutan,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I do not think your question is related to Aspsoe.Words. There is several approaches, which you can use to parse your XML. If it is valid XML, you can use XmlReader for example. But since XML tags in your document can be improperly formatted, I think, it is better to use regular expressions to parse these tags.

Best regards.