Modify a single XML attribute in C #

I have written the XML document very well, it will look like this




I I’m trying to find a way to access the “class” attribute of a single character and modify it. So far, I have reached the point where I can pinpoint a specific character, but I can’t figure out how to access the’Class’ attribute and modify it for char It.

void Write(string path, string charName, string varToChange, string value){

XmlNode curNode = null;
XmlDocument doc = new XmlDocument();
doc.Load(path);

XmlElement rootDoc ​​= doc.DocumentElement;
curNode = rootDoc;

if (curNode.HasChildNodes){

for(int i=0; i
if(charName == curNode.ChildNodes[i ].Attributes.GetNamedItem("Name").Value){

// Code would go here
}
}
}
return;< br />}

Use XPATH:

< pre>XmlDocument doc = new XmlDocument();
doc.Load(path);

var nodes = doc.SelectNodes(String.Format(“/Team/Character[@Name=\ “{0}\”]”, charName));

foreach (XmlElement n in nodes)
{
n.SetAttribute(varToChange, value);
}

I have written the XML document very well, it will look like this

 


I’m trying to find a way to access the “class” attribute of a single character and modify it. So far, I have reached the point where I can pinpoint a specific character, but I can’t figure out how to access the’Class’ Attribute and modify it for char.

void Write(string path, string charName, string varToChange, string value){

XmlNode curNode = null;
XmlDocument doc = new XmlDocument();
doc.Load(path);

XmlElement rootDoc ​​= doc.DocumentElement;
curNode = rootDoc;

if(curNode.HasChildNodes){

for(int i=0; i
if(charName == curNode.ChildNodes[i].Attribut es.GetNamedItem("Name").Value){

// Code would go here
}
}
}
return;
}

Use XPATH:

XmlDocument doc = new XmlDocument();
doc.Load(path);

var nodes = doc.SelectNodes(String.Format("/Team/Character[@Name=\"{0}\"]", charName)) ;

foreach (XmlElement n in nodes)
{
n.SetAttribute(varToChange, value);
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3101 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.