デフォルトの名前空間をルートに追加しようと何度か試みましたが、その子にも名前空間が追加されます。名前空間を既存の XDocument に追加したいと考えています。
私のコードは試みます。
// add default namespace - attempt 1
XNamespace xmlns = "http://www.myschema/schema.xsd";
xDocument.Root.Name = xmlns + xDocument.Root.Name.LocalName;
// add default namespace - attempt 2
XNamespace MyNS = "http://www.myschema/schema.xsd";
xDocument.Element("testFile").Name = MyNS.GetName("testFile");
XML;
<testFile version="1" xmlns="http://www.myschema/schema.xsd">
<testResults xmlns=""> <!-- *** Unwanted Attribute *** -->
<result resultID="abcdefgh" comment="blah blah blah blah">
</testResults>
</testFile>
testResults に xmlns 名前空間属性が付加されている理由を知りたいですか?
テスト対象のテスト C# コードを次に示します。
XDocument xDocument = new XDocument(
new XElement("testFile",
new XAttribute("version", "1"),
new XElement("testResults",
new XElement("result",
new XAttribute("resultID", "abcdefgh"),
new XAttribute("comment", "blah blah blah blah")
))));