LoginSignup
1
1

More than 5 years have passed since last update.

XmlDocument.DocumentTypeを変更する

Posted at

XmlDocumentオブジェクトにある DocumentTypeを変更したい場合は、そのnodeを置き換えなければならない。

XmlDocument document = new XmlDocument();
document.Load( "test.xml" );

XmlDocumentType newType = new document.CreateType("new", "", "", ""); // 新しいDocumentType
XmlDocumentType oldType = document.DocumentType; // 古いDocumentType
document.ReplaceChild(newType, oldType);

のようにする。
ここで、DocumentTypeのNodeはElementsのNodeより先に配置されていないと、document.DocumentTypeでnullが返ってきてしまうようになる。
なので、RemoveChild(oldType) -> AppendChild(newType)という方法では、DocumentTypeのノードが最後尾に回されてしまうため駄目。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1