次のような XML ドキュメントを作成できる必要があります。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rootprefix:rootname
noPrefix="attribute with no prefix"
firstprefix:attrOne="first atrribute"
secondprefix:attrTwo="second atrribute with different prefix">
...other elements...
</rootprefix:rootname>
これが私のコードです:
XmlDocument doc = new XmlDocument();
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
doc.AppendChild(declaration);
XmlElement root = doc.CreateElement("rootprefix:rootname", nameSpaceURL);
root.SetAttribute("schemaVersion", "1.0");
root.SetAttribute("firstprefix:attrOne", "first attribute");
root.SetAttribute("secondprefix:attrTwo", "second attribute with different prefix");
doc.AppendChild(root);
残念ながら、2 番目のプレフィックスを持つ 2 番目の属性で得られるのは、まったくプレフィックスではありません。schemaVersion 属性のように、単なる「attrTwo」です。
では、C# のルート要素の属性に異なるプレフィックスを付ける方法はありますか?