EDN Admin
Well-known member
Im trying to read a XElement from XDocument and then trying to set its Value. I tried several approaches but im not able to read the element from XDocument, it always return NULL. Here is the XML and the code
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; AppealRoot <span style="color:Red; xmlns:xsi<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/2001/XMLSchema-instance<span style="color:Black; " <span style="color:Red; xmlns:xsd<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/2001/XMLSchema<span style="color:Black; " <span style="color:Red; xmlns<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://tempuri.org/XMLSchema1.xsd<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppealForm<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Id <span style="color:Red; xsi:nil<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; Salary <span style="color:Red; xsi:nil<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FullName <span style="color:Red; xsi:nil<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FirstName<span style="color:Blue; >James<span style="color:Blue; </<span style="color:#A31515; FirstName<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; MiddleName<span style="color:Blue; >L<span style="color:Blue; </<span style="color:#A31515; MiddleName<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppealForm<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppealRoot<span style="color:Blue; >
[/code]
<div style="color:Black;background-color:White; <pre>
XDocument xDoc = XDocument.Load(<span style="color:#A31515; @"Cutput.xml");
XNamespace ns = xDoc.Root.Name.Namespace;
XElement elm = xDoc.Element(ns + <span style="color:#A31515; "Salary");
<span style="color:Blue; if (elm != <span style="color:Blue; null)
elm.SetValue(110000);
xDoc.Save(<span style="color:#A31515; @"Cutput2.xml");
[/code]
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; AppealRoot <span style="color:Red; xmlns:xsi<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/2001/XMLSchema-instance<span style="color:Black; " <span style="color:Red; xmlns:xsd<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/2001/XMLSchema<span style="color:Black; " <span style="color:Red; xmlns<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://tempuri.org/XMLSchema1.xsd<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; AppealForm<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Id <span style="color:Red; xsi:nil<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; Salary <span style="color:Red; xsi:nil<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FullName <span style="color:Red; xsi:nil<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; true<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FirstName<span style="color:Blue; >James<span style="color:Blue; </<span style="color:#A31515; FirstName<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; MiddleName<span style="color:Blue; >L<span style="color:Blue; </<span style="color:#A31515; MiddleName<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppealForm<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; AppealRoot<span style="color:Blue; >
[/code]
<div style="color:Black;background-color:White; <pre>
XDocument xDoc = XDocument.Load(<span style="color:#A31515; @"Cutput.xml");
XNamespace ns = xDoc.Root.Name.Namespace;
XElement elm = xDoc.Element(ns + <span style="color:#A31515; "Salary");
<span style="color:Blue; if (elm != <span style="color:Blue; null)
elm.SetValue(110000);
xDoc.Save(<span style="color:#A31515; @"Cutput2.xml");
[/code]
View the full article