私は奇妙な状況に出くわしました。私よりもよく理解している誰かがそれを解決するのを手伝ってくれることを願っています.
Microsoft Word で開くことができるように、Xml ドキュメントに画像を挿入しています。この一環として、画像を含む要素にマップする Xml 'Relationship' を追加する必要があります。簡単です。
次のようなノードを追加しています。
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.png" />
ただし、最終的な .doc ファイルでは、同じ行が次のように表示されます。
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.png" xmlns="" />
つまり、空の xmlns="" 属性が含まれるようになりました。
これは、Word が文書が破損していると判断し、開くことを拒否するのに十分です。ファイルを手動で開いてその属性を削除すると、ファイルが開きます。
明らかに、プログラムで削除したいのです:-)だから、親ノードを見つけました。これは私の理解が少しぼやけているところです。OuterXml要素にはノードとそのすべての子のコンテンツが含まれ、InnerXmlには単に子が含まれていると信じていました。
これが私が見ているものです (エスケープ文字は、Visual Studio のテキスト ビューアーから切り取ったためであることに注意してください)。
OuterXml:
"<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">
<Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings\" Target=\"webSettings.xml\" />
<Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\" Target=\"settings.xml\" />
<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\" />
<Relationship Id=\"rId5\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\" Target=\"theme/theme1.xml\" />
<Relationship Id=\"rId4\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable\" Target=\"fontTable.xml\" />
<Relationship Id=\"rId6\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"media/image1.png\" xmlns=\"\" />
</Relationships>"
インナーXml:
"<Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings\" Target=\"webSettings.xml\" xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\" />
<Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\" Target=\"settings.xml\" xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\" />
<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\" xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\" />
<Relationship Id=\"rId5\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\" Target=\"theme/theme1.xml\" xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\" />
<Relationship Id=\"rId4\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable\" Target=\"fontTable.xml\" xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\" />
<Relationship Id=\"rId6\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image\" Target=\"media/image1.png\" />"
6 番目の最後の要素の OuterXml には誤った xmlns="" が含まれているが、InnerXml には含まれていないことに注意してください。InnerXml は簡単に変更できますが、OuterXml は変更できません。
したがって、私の究極の質問は「この追加された属性を取り除くにはどうすればよいですか?」ですが、(コンテナは別として) 内部と外部の Xml に違いがある理由を誰かが説明できることを願っています。