logo
search
Others

How to Fix Power Automate XML Errors from Invalid HTML

Huda QurayshiHuda Qurayshi Oct 15, 2026 869 views

Question details

The user needs to resolve an invalid XML error in Power Automate triggered when parsing poorly formatted HTML from email messages.

How to Fix Power Automate XML Errors from Invalid HTML
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.
Before you start

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.

Solution 1Recommended

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.

1
Locate the source output

In your Flow run history, inspect the raw outputs of the email connector or action that generates the HTML content.

2
Identify malformed tags

Look for elements that lack a closing tag, such as <img> missing a trailing slash or <br> tags instead of <br />.

3
Apply replace expressions

Add a 'Compose' action and use the replace() expression to dynamically fix formatting. For example: replace(variables('HTML'), '<img>', '<img />').

4
Escape special characters

Ensure any standalone ampersands (&) in URLs or text are replaced with their proper entity (&amp;) to prevent XML parsing failures.

Inspect and Sanitize the Source HTML
Nested Replaces: You can nest multiple replace() functions together in one expression to fix several different tag errors simultaneously.
Free Microsoft Office alternative

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. 1. Visit the official site: Go to the official WPS Office website to access the download page.
  2. 2. Download the installer: Click on 'Download' to get the lightweight installation file for your operating system.
  3. 3. Install and start working: Run the installer, follow the simple on-screen instructions, and start editing your documents immediately.
Fully compatible with Microsoft Office formats (.docx, .xlsx, .pptx).Lightweight design ensures fast launch times and smooth document editing.Familiar user interface requires no learning curve for Microsoft users.Free built-in PDF reader and editor to streamline your daily workflow.
microsoft office alternative - wps office

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.