Skip to content

Commit

Permalink
Merge pull request #21 from jbrayfaithlife/issue/#20
Browse files Browse the repository at this point in the history
Auto-identify the XML namespace Issue 20
  • Loading branch information
FlorianRappl authored Aug 24, 2023
2 parents 65fc194 + 41138b9 commit 274e8d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/AngleSharp.Xml.Tests/Parser/XmlParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,13 @@ public void ParseInvalidXmlShouldNotThrowWhenSuppressingErrors_Issue14()
parser.ParseDocument(source);
});
}

[Test]
public async Task XmlPrefixedAttributesShouldLocateXmlNamespaceWithoutDeclaration()
{
var document = @"<xml xml:lang=""en""></xml>".ToXmlDocument();
var root = document.DocumentElement;
Assert.AreEqual(NamespaceNames.XmlUri, root.Attributes.Single().NamespaceUri);
}
}
}
6 changes: 5 additions & 1 deletion src/AngleSharp.Xml/Parser/XmlDomBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,11 @@ private Attr CreateAttribute(String name, String value)
var prefix = name.Substring(0, colon);
var ns = NamespaceNames.XmlNsUri;

if (!prefix.Is(NamespaceNames.XmlNsPrefix))
if (prefix.Is(NamespaceNames.XmlPrefix))
{
ns = NamespaceNames.XmlUri;
}
else if (!prefix.Is(NamespaceNames.XmlNsPrefix))
{
ns = CurrentNode.LookupNamespaceUri(prefix);
}
Expand Down

0 comments on commit 274e8d9

Please sign in to comment.