我用XmlDocument构建了一个xml对象xmlObj,内容如下
<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
<channel>
<title>Google Ad Express</title>
<item>
<title>csdn</title>
<link>www.csdn.net</link>
<description>csdn</description>
<g:param name="price">33.99</g:param>
</item>
</channel>
</rss>
调用xmlObj.Save("D:/test.xml")后,生成了test.xml,但打开文件后发现g:param节点的前缀不见了,成了这样
<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
<channel>
<title>Google Ad Express</title>
<item>
<title>csdn</title>
<link>www.csdn.net</link>
<description>csdn</description>
<param name="price">33.99</param>
</item>
</channel>
</rss>请问各位大虾有没有遇到过这个问题,应该怎么解决?我想保存后仍然保留前缀

解决方案 »

  1.   

    <?xml version="1.0" encoding="iso-8859-1" ?>
    <rss version="2.0" xmlns:g="http://xxx/">
    <channel>
    <title>Google Ad Express</title>
    <item>
    <title>csdn</title>
    <link>www.csdn.net</link>
    <description>csdn</description>
    <g:param name="price">33.99</g:param>
    </item>
    </channel>
    </rss>
      

  2.   

    加上了,好像还是没有作用,我是用XmlElement来创佳<channel>下的所有节点的
      

  3.   

    我试图直接设置item节点的InnerXml,提示说'g' is an undeclared namespace
    看来是namespace的问题,但我试了很多方法,都不知道怎么添加这个namespace
      

  4.   

    node1 = doc.CreateNode(XmlNodeType.Element, "g", "param", "http://dotnet.aspx.cc/")