日期:2014-05-20  浏览次数:20436 次

求教在asp.net添加xml的子节点问题??????
我的原意是在jsxie.xml文件中
再添加个 <test>
                  ......            
                  </test>
可是我运行jsxie.aspx后   jsxie.xml没有再添加个 <test> 节点
jsxie.xml

<?xml   version= "1.0 "   standalone= "yes "?>
<test>
    <id> 3 </id>
    <usern> koko </usern>
    <mima> koko </mima>
</test>


jsxie.aspx

script   runat= "server ">
        Sub   Page_Load(ByVal   Sender   As   Object,   ByVal   E   As   EventArgs)
               
                Dim   stxml   As   XmlDocument   =   New   XmlDocument()
                stxml.Load(Server.MapPath( "jsxie.xml "))
                         
                Dim   ss   As   XmlNode   =   stxml.CreateElement( "test ")
                Dim   el   As   XmlElement   =   stxml.CreateElement( "id ")
                el.InnerText   =   "001 "
                Dim   xesub1   As   XmlElement   =   stxml.CreateElement( "usern ")
                xesub1.InnerText   =   "me "
                Dim   xesub2   As   XmlElement   =   stxml.CreateElement( "mima ")
                xesub2.InnerText   =   "no "
                ss.AppendChild(el)
                ss.AppendChild(xesub1)
                ss.AppendChild(xesub2)
                stxml.Save(Server.MapPath( "jsxie.xml "))
   
        End   Sub
</script>

------解决方案--------------------
加上 stxml.AppendChild(ss)
------解决方案--------------------
差不多就这个意思,xmldocument只允许一个根节点,可能你要重新组织一下。
stxml.DocumentElement.AppendChild(ss)

------解决方案--------------------
<?xml version= "1.0 " standalone= "yes " ?>
- <tests>
- <test>
<id> 3 </id>
<usern> koko </usern>
<mima> koko </mima>
</test>
- <test>
<id> 25 </id>
<usern> volo </usern>
<mima> volo </mima>
</test>
</tests>
------解决方案--------------------
楼主 你的那个是从数据库里转换过来的吗 ??? 怎么连根接点都没有啊