-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Closed
Copy link
Labels
Milestone
Description
Description
As described in the title.
XmlWriterSettings.NewLineOnAttributes is applied to normal attributes properly, but seems not to be applied to xmlns attributes.
This problem seems to occur with both case of xmlns="..." and xmlns:nsname="...".
Reproduction Steps
Code for reproduction:
using System.Xml;
using System.Xml.Linq;
var nsSvg = (XNamespace)"http://www.w3.org/2000/svg";
var nsXLink = (XNamespace)"http://www.w3.org/1999/xlink";
var doc = new XDocument(
new XDeclaration("1.0", "utf-8", null),
new XElement(
nsSvg + "svg",
new XAttribute("version", "1.1"),
new XAttribute("width", "10"),
new XAttribute(XNamespace.Xmlns + "xlink", nsXLink.NamespaceName),
new XAttribute("height", "10"),
new XElement(nsSvg + "g")
)
);
var settings = new XmlWriterSettings() {
CloseOutput = false,
Indent = true,
IndentChars = " ",
NewLineChars = "\n",
NewLineOnAttributes = true
};
using (var writer = XmlWriter.Create(Console.Out, settings)) {
doc.Save(writer);
}
Console.WriteLine();Note: The same problem occurs with XDocument created from XDocument.Load.
var reader = new StringReader(@"<?xml version=""1.0"" encoding=""utf-8""?>
<svg
version=""1.1""
xmlns=""http://www.w3.org/2000/svg""
width=""10""
xmlns:xlink=""http://www.w3.org/1999/xlink""
height=""10""
>
<g />
</svg>
");
var doc = XDocument.Load(reader);Expected behavior
<?xml version="1.0" encoding="utf-8"?>
<svg
version="1.1"
width="10"
xmlns:xlink="http://www.w3.org/1999/xlink"
height="10"
xmlns="http://www.w3.org/2000/svg">
<g />
</svg>Actual behavior
<?xml version="1.0" encoding="utf-8"?>
<svg
version="1.1"
width="10" xmlns:xlink="http://www.w3.org/1999/xlink"
height="10" xmlns="http://www.w3.org/2000/svg">
<g />
</svg>Regression?
No response
Known Workarounds
No response
Configuration
$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.400
Commit: 7771abd614
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /usr/share/dotnet/sdk/6.0.400/
global.json file:
Not found
Host:
Version: 6.0.8
Architecture: x64
Commit: 55fb7ef977
*snip*
Other information
No response
Reactions are currently unavailable