寫入函數如下??public?static?void?writexml(string?wstring)//寫入????????{????????????XmlDocument?xmlDoc?=?new?XmlDocument();????????????xmlDoc.Load("bookstore.xml");????????????XmlNodeList?nls?=?xmlDoc.SelectSingleNode("/bookstore/book").ChildNodes;//獲取bookstore節點的所有子節點?????????????????????????foreach?(XmlNode?xn1?in?nls)//遍歷????????????????????{????????????????XmlElement?xe2?=?(XmlElement)xn1;//將子節點類型轉換為XmlElement類型?????????????????if?(xn1.Name?==?"author")//如果找到??????????????????????????????????{???????????????????xe2.InnerText?=?wstring;????????????????????break;//找到退出來就可以了????????????????????????}????????????}?????????????}執行代碼如下string?Desconstring?=?"1225555558745";????????????Maticsoft.DBUtility.PubConstant.writexml(Desconstring);????????????MessageBox.Show("配置完成");執行代碼?沒有報錯,但author?的innertext并沒有任何改變,我的代碼到底錯在那里,請大師指正,謝謝
5 回答

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
應該是沒有找到任何節點
XmlNodeList?nls?=?xmlDoc.SelectSingleNode("/bookstore/book").ChildNodes;//獲取bookstore節點的所有子節點
改為:XmlNodeList?nls?=?xmlDoc.SelectSingleNode("bookstore").ChildNodes;這樣寫才是獲取bookstore節點下的所有子節點
? ? ? ? ? ?
- 5 回答
- 0 關注
- 489 瀏覽
添加回答
舉報
0/150
提交
取消