Normally XML elements to get edited on web page are sent over as the input name Example :
Then In C# controller method:
List<string> keys = Request.Form.Keys.Cast<string>().Where(item => item[0] == '/' && item[1] == '/').ToList();
foreach (var key in keys)
{
var item = xDoc.SelectSingleNode(key, manager);
if (item != null)
item.InnerText = Request.Form[key];
else
throw new InvalidOperationException("Could not decode parameter with key " + key + " and value " + Request.Form[key]);
}
Normally the XML elements are sent over in a Request.Form part of a Key Collection, thus 1 key example is:
"//IVS-NONINST-REC/IVS-NONINST-REC-REST[1]/IVS-SEC-DIAG-CDS[1]/IVS-SEC-DIAG-T[1]"
However, there are Attributes that I need to send over to have those parsed over and saved as well. I'm not sure how to send them over "properly" and if I send attribute over like
"//IVS-NONINST-REC/IVS-NONINST-REC-REST[1]/IVS-SEC-DIAG-CDS[1]/IVS-SEC-DIAG-T[1]/IVS-SEC-DIAG"
The code loop hits the throw new InvalidOperationException.
- How can I properly send over the attributes?
- How can I properly parse over the attributes in C# to save them?
The XML for that element and its attribute looks like this
<IVS-SEC-DIAG-T IVS-SEC-DIAG="C56.9" IVS-SEC-POA="">test</IVS-SEC-DIAG-T>
Update, complete xml (deleted some for brevity)
<IVS-NONINST-REC xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<IVS-NONINST-REC-KEY IVS-REC-TYP="2" IVS-TM-STAMP="210549" IVS-ADJ-KEY="5">
</IVS-NONINST-REC-KEY>
<IVS-NONINST-REC-REST IVS-PAT-ID="333089302">
<IVS-SEC-DIAG-CDS>
<IVS-SEC-DIAG-T IVS-SEC-DIAG="C56.9" IVS-SEC-POA="">test</IVS-SEC-DIAG-T>
</IVS-NONINST-REC-REST>
</IVS-NONINST-REC>
While I can see all the xml elements and attributes in the xDoc InnerHTML, the xDoc thinks there are no attributes Here is a screencap