5
próbowałem dwa sposoby, ale oboje nie działał .. pierwszy sposób ::xml węzły edytowanie na podstawie XMLELEMENT
string filepath = Server.MapPath[this is not a link]("XMLFile2.xml");
XmlDocument xdoc = new XmlDocument();
xdoc.Load(filepath);
XmlNode root = xdoc.DocumentElement;
XmlNode idNode = root.SelectSingleNode("/students/student/id");
if (idNode.Value == 9.ToString())
{
var nodeOfStudent = xdoc.SelectNodes("/students/student[@id='9']");
nodeOfStudent[1].InnerXml = TextBox_firstname.Text;
nodeOfStudent[2].InnerXml = TextBox_lastname.Text;
nodeOfStudent[3].InnerXml = TextBox_dob.Text;
nodeOfStudent[4].InnerXml = TextBox_class.Text;
nodeOfStudent[5].InnerXml = TextBox_section.Text;
nodeOfStudent[6].InnerXml = TextBox_telephone.Text;
}
drugi sposób ::
string filepath = Server.MapPath("XMLFile2.xml");
XmlDocument xdoc = new XmlDocument();
xdoc.Load(filepath);
XmlNode root = xdoc.DocumentElement;
XmlNode idNode = root.SelectSingleNode("/students/student/id");
xdoc.SelectSingleNode("/students/student[@id='10']/firstname").InnerXml = TextBox_firstname.Text;
xdoc.DocumentElement.AppendChild(firstname);
xdoc.SelectSingleNode("/students/student[@id='10']/lastname").InnerXml = TextBox_firstname.Text;
xdoc.SelectSingleNode("/students/student[@id='10']/dob").InnerXml = TextBox_firstname.Text;
xdoc.SelectSingleNode("/students/student[@id='10']/class").InnerXml = TextBox_firstname.Text;
xdoc.SelectSingleNode("/students/student[@id='10']/section").InnerXml = TextBox_firstname.Text;
xdoc.SelectSingleNode("/students/student[@id='10']/telephone").InnerXml = TextBox_firstname.Text;
xdoc.Save(filepath);
jest coś złego nie widzę ... mój plik xml wygląda następująco ::
<students>
<student>
<id>1</id>
<first_name>ahmad</first_name>
<last_name>hani</last_name>
<DOB>12/5/1998</DOB>
<class>sixth</class>
<section>A</section>
<telephone>06555632</telephone>
</student>
</students>
i użyłem str zapytania Aby załadować wartości z gridView znajduje się na innej stronie przy użyciu "QueryString" ....
z góry dzięki.
chcę filtrować mojego kodu na podstawie identyfikatora wartości XMLELEMENT ,, ale nie wydaje się działać !!! XmlDocument xdoc = new XmlDocument(); xdoc.Load (ścieżka do pliku); XmlNode root = xdoc.DocumentElement; XmlNode idNode = root.SelectSingleNode ("/ students/student/id"); if (idNode.Value == null) {utwórz nowy węzeł xml} else if (idNode.Value! = Null) {utwórz nowy element xml o wartości id) Próbowałem wyjaśnić to pytanie , tutaj jest link ... http://stackoverflow.com/questions/13607387/edit-xml-elements-of-i-specific-node-based-on-its-id-element-asp-net-page –