私はこのようなXML文書を作成できるようにする必要があります。C#で異なる接頭辞/名前空間を持つ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番目のプレフィックスを有する第二の属性のために取得していますどのような接頭辞はまったくありません。それはちょうど "attrTwo" - schemaVersion属性のようなものです。
したがって、C#のルート要素の属性に異なる接頭辞を付ける方法はありますか?
名前テーブルとAddNameSpaceはあなたではなく、デフォルトの命名規則を名前空間の短縮を決定する必要がある場合にのみ必要とされていることは注目に値する(d1p1、d1p2、...) –