AngleSharp/AngleSharp.Xml

XmlParser InnerHtml property not working

Wojdav opened this issue · 5 comments

when i have used innerHtml property on xmlElement i didn't have any results.

exmple code

var xmlParser = new XmlParser();
var xmlDocument = xmlParser.Parse("<div></div>");
var querySelector = xmlDocument.QuerySelector("div");

querySelector.InnerHtml = "<a></a>";

TestContext.WriteLine(xmlDocument.ToHtml());

result <div></div>

The InnerHtml property is related to HTML; while serializing still works the fragment parsing mode is only defined for HTML. Same holds true for, e.g., OuterHtml.

I'll see if this can be improved.

CreateForeignElementFrom method (htmlDomBuilder.cs, 3423 line) returns null. This is the problem.

Best Regards

Nope, this is not the problem. The problem is that this is not defined for XML (thus the HTML DOM Builder should not be used). Please do not confuse XML with HTML or vice versa.

Right now I think it can't be done efficiently. The DocumentFragment always assumes to be in an HTML environment, however, as ParseFragment is/was not defined for XML (in AngleSharp) I don't see how we can support both in an elegant and robust way.

I will implement a solution for v1!

Landed in devel - scheduled for next release.