C# Edit XML, I am totally lost -



C# Edit XML, I am totally lost -

i have code load xml files not sure of if complete. code.

public void updatexml(string xmlfile, string choosenode, string choosesinglenode, string newnode, string selectedcategory) { xmldocument xml = new xmldocument(); xml.load(xmlfile); foreach (xmlelement element in xml.selectnodes(choosenode)) { foreach (xmlelement element1 in element) { if (element.selectsinglenode(choosenode).innertext == selectedcategory) { xmlnode newvalue = xml.createelement(newnode); newvalue.innertext = "modified"; element.replacechild(newvalue, element1); xml.save(xmlfile); } } }

below method utilize in end, set xmlfile , such. (the updatexml method in "data.cs", called on repository.

public void editcategory(string newnode) { string xmlfile = "category.xml"; string choosenodes = "arrayofcategory/category"; string choosesinglenode = "//name"; string selectedcategory = "news"; repository.update(xmlfile, choosenodes, newnode, choosesinglenode, selectedcategory); }

i unsure of set in diffrent nodes etc, code above found here on stackoverflow. - below xmlfile want edit.

<?xml version="1.0" encoding="utf-8"?> <arrayofcategory xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <category> <id>6b30511d-2cd1-4325-ad73-7b905f76ffc0</id> <name>news</name> </category> <category> <id>516401f4-b45c-46ef-b8f4-9d05021ae794</id> <name>pods</name> </category> <category> <id>0c9cd216-86cf-4a62-884c-1b428150ebac</id> <name>pods</name> </category> </arrayofcategory>

i appreciate help.

if (element.selectsinglenode(choosenode).innertext == selectedcategory)

choosenode = "arrayofcategory/category"

selectedcategory = "news";

so innertext of choosenode never "news" because "news" under <name>

c# xml

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -