Embedding XML (with XML declaration) in HTML or other XML Embedding XML (with XML declaration) in HTML or other XML xml xml

Embedding XML (with XML declaration) in HTML or other XML


General answer

When XML declarations (<?xml version="1.0" ?>) appear anywhere other than at the very top of an XML document, parsers often confuse them with processing instructions and issue misleading error messages.

The canonical answer for fixing your error,

Error Traced[line: 4302] The processing instruction target matching "[xX][mM][lL]" is not allowed.

and all similar errors related to XML declarations is covered by this Q/A:

There you'll find solutions to the three causes of such errors:

  1. Visible content before the XML declaration
  2. Invisible content before the XML declaration
  3. Duplicate XML declarations

Suggestions for your particular case

Trying wrapping your code within script with CDATA:

<script>//<![CDATA[    ...code containing XML declaration (`<?xml version="1.0"?>`)//]]></script>

so that the XML declaration isn't interpreted to be part of the enclosing document. XML declarations can only appear at the very top of an XML document (and there can only be one of them at most).

If that doesn't resolve your problem, examine where you're outputting the XML declaration. Make sure that there is no visible or invisible content ahead of the XML declaration, and make sure that there are not multiple XML declarations in the output. For more details see:


This can also happen if you have duplicate xml tag <?xml version="1.0"...> defined accidentally


This error can also happen if you have blank space before your xml , happened to me in sending xml request with postman,

Removing blank space before request solved the issue.