using SetValue method in XML



I have the following XML:



<?xml version="1.0" encoding="UTF-8"?>
<TRANSACTION>
<FIELDS>
<FIELD KEY="first_name"></FIELD>
<FIELD KEY="last_name"></FIELD>
<FIELD KEY="state"></FIELD>
</FIELDS>
</TRANSACTION>


Using C# I am using XDocument.Parse to create a var and trying to update it with user-entered values via the XDocument, SetValue() method (so the input data is normalized) but I'm having a challenge in trying to traverse the schema. I'd like to have the result to look like:



<?xml version="1.0" encoding="UTF-8"?>
<TRANSACTION>
<FIELDS>
<FIELD KEY="first_name">John</FIELD>
<FIELD KEY="last_name">Doe</FIELD>
<FIELD KEY="state">CA</FIELD>
</FIELDS>
</TRANSACTION>


Any suggestions are appreciated. Thanks


No comments:

Post a Comment