Bug Report
Prerequisites
For more information, see the CONTRIBUTING guide.
Description
I have a self-closing element and now want to add a child element.
Steps to Reproduce
Here's a complete repo:
[TestMethod]
public void TestInsertChildToSelfClosingElementSimple()
{
var xml =
"""
<ac:structured-macro ac:name="children"/>
""";
var config = Configuration.Default.With(HtmlEntityProvider.Resolver).WithDefaultLoader(new LoaderOptions { IsResourceLoadingEnabled = true }).WithCss().WithXml();
var context = BrowsingContext.New(config);
var parser = new XmlParser(new XmlParserOptions(), context);
var doc = parser.ParseDocument(xml);
var parentElement = doc.DocumentElement;
Assert.IsNotNull(parentElement);
Assert.AreEqual(NodeFlags.SelfClosing, parentElement.Flags);
var child = doc.CreateElement("ac:parameter");
child.SetAttribute("ac:name", "dummy");
parentElement.AppendChild(child);
var parentElementXml = parentElement.ToXml();
// it seems to be impossible to insert something into a self-closing element!? this test is here to document this fact
Assert.AreEqual("""<ac:structured-macro ac:name="children" /><ac:parameter ac:name="dummy"></ac:parameter>""", parentElementXml);
}
Expected behavior: I expect the ac:parameter element to become a child element of the parent element. The outcome should look like this: <ac:structured-macro ac:name="children"><ac:parameter ac:name="dummy"></ac:parameter></ac:structured-macro>.
Actual behavior: The ac:parameter element is inserted as sibling instead: <ac:structured-macro ac:name="children" /><ac:parameter ac:name="dummy"></ac:parameter>.
Environment details: .NET 8, Windows 11 && Debian
Possible Solution
Cloning
I'd be fine with cloning the element if I could specify if the clone should be self-closing, or not. Basically optionally introduce the behavior that was once fixed here: #17 :D
I tried finding some specs that describe if it is valid to "transform" a self-closing element back to having children, but couldn't find anything. Cloning might introduce a compliant workaround if any specs prohibit changing the self-closing flag.
Changing the Flag
Maybe it is as easy as allowing to change the Flags property. Not sure about the consequences, though.
Bug Report
Prerequisites
AngleSharp.Cssfor CSS support)For more information, see the
CONTRIBUTINGguide.Description
I have a self-closing element and now want to add a child element.
Steps to Reproduce
Here's a complete repo:
Expected behavior: I expect the
ac:parameterelement to become a child element of the parent element. The outcome should look like this:<ac:structured-macro ac:name="children"><ac:parameter ac:name="dummy"></ac:parameter></ac:structured-macro>.Actual behavior: The
ac:parameterelement is inserted as sibling instead:<ac:structured-macro ac:name="children" /><ac:parameter ac:name="dummy"></ac:parameter>.Environment details: .NET 8, Windows 11 && Debian
Possible Solution
Cloning
I'd be fine with cloning the element if I could specify if the clone should be self-closing, or not. Basically optionally introduce the behavior that was once fixed here: #17 :D
I tried finding some specs that describe if it is valid to "transform" a self-closing element back to having children, but couldn't find anything. Cloning might introduce a compliant workaround if any specs prohibit changing the self-closing flag.
Changing the Flag
Maybe it is as easy as allowing to change the Flags property. Not sure about the consequences, though.