How to Fix Power Automate XML Errors from Invalid HTML
Question details
The user needs to resolve an invalid XML error in Power Automate triggered when parsing poorly formatted HTML from email messages.

- Product
- Microsoft Power Automate
- Device & OS
- not provided
- Scenario
- Using the xml() function in Power Automate to parse HTML content extracted from emails.
- Observed behavior
- Power Automate throws an invalid XML error because the source HTML contains improperly closed elements like image tags or mismatched anchor tags.
Identify the exact step in your Power Automate flow where the HTML is being converted, and keep a sample of the raw HTML source handy to check for broken tags.
Inspect and Sanitize the Source HTML
Use Power Automate expressions to clean and properly format the HTML tags before passing the content to the xml() function.
Web browsers and email clients are forgiving with malformed HTML, but XML parsers are strictly enforced. Every tag must be properly closed.
In your Flow run history, inspect the raw outputs of the email connector or action that generates the HTML content.
Look for elements that lack a closing tag, such as <img> missing a trailing slash or <br> tags instead of <br />.
Add a 'Compose' action and use the replace() expression to dynamically fix formatting. For example: replace(variables('HTML'), '<img>', '<img />').
Ensure any standalone ampersands (&) in URLs or text are replaced with their proper entity (&) to prevent XML parsing failures.

Consult the Power Automate Community
Seek advanced flow configurations and pre-built regular expressions from the official community forum.
Looking for a seamless Office experience? Try WPS Office
While Power Automate handles automated workflows, your daily document tasks require a robust office suite. WPS Office provides a lightweight, free alternative to Microsoft Office with full compatibility for Word, Excel, and PowerPoint files.
- 1. Visit the official site: Go to the official WPS Office website to access the download page.
- 2. Download the installer: Click on 'Download' to get the lightweight installation file for your operating system.
- 3. Install and start working: Run the installer, follow the simple on-screen instructions, and start editing your documents immediately.

Frequently Asked Questions
Why does valid HTML cause an XML error in Power Automate?
HTML and XML have different strictness levels. While email clients easily render poorly formed HTML (like unclosed <br> or <img> tags), the xml() function in Power Automate requires strictly well-formed XML where every opening tag has a matching closing tag.
Can I use Power Automate to automatically clean HTML from emails?
Yes, you can use a series of replace() expressions in your Flow's 'Compose' action to find unclosed tags and replace them with properly closed equivalents before passing the content to the XML parser.
Are there automated connectors to convert HTML to XML?
Yes, there are third-party premium connectors available in Power Automate, such as Plumsail or Muhimbi, which can safely parse or convert raw HTML into clean documents without manually writing XML sanitization expressions.




