I'm working on retrieving some xhtml content at run time and displaying that within an iframe element of an html page. The problem which I'm trying to solve here is the title tag which is part of the xhtml content is being passed as a self closing tag (<title/>) and when the content is passed into iframe, it is being consumed as html which is resulting in the content not being displayed at all within iframe.
Adding a screenshot of the dom below for reference:

Please note that when I am trying to consume the xhtml content after storing it as a separate xhtml file and retrieving it using the src tag (specifying the path to the same), the xml parsing is correctly done and I could see the text content being displayed as well. But unfortunately, the content is actually getting generated in real time in the real scenario where I'm trying to fix it so using src attribute is not an option.
I also tried accessing the contentDocument of the iframe and adding the xml content directly there but even that doesn't seem to be solving the problem.
Does somebody know of any workaround for addressing this problem?
Thanks in advance.
The srcdoc attribute assumes "text/html" content type. Consider using the src attribute with a data: url like this:
<iframe src="data:application/xhtml+xml,
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title/>
</head>
<body>
<p>Hello world</p>
</body>
</html>">
</iframe>