当前位置:编程学习 > C#/ASP.NET >>

怎样在属性前加命名空间呢

最近开发的项目需要用C#修改xml,遇到要属性前面有命名空间的,对xml不够熟悉,SetAttribute总是不能实现。
代码如下
C#:
 private void Add_activity(string aName,string Path)
         {
             

             XmlDocument doc = new XmlDocument();
             // 装入指定的XML文档  

             doc.Load(Path);
             XmlNode manifest = doc.SelectSingleNode("manifest");
             XmlNode application = manifest.SelectSingleNode("application");
             
             //创建一个新的元素.
             
             XmlElement elem = doc.CreateElement("activity");
             elem.SetAttribute("android:name", aName);
            
             elem.InnerText = "";
             

             //添加新的元素
             application.AppendChild(elem);

             //关闭打开的文档
             doc.Save(Path);
        }
XML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.next"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我试过用elem.SetAttribute("name","android", aName);
但是得出的效果却是<activity d3p1:name="dafgadsg" xmlns:d3p1="android" xmlns="android">
求高手来打救一下
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,