Reputation: 184
I have this form of text string
<remittance><contain><blrn>032398106/17/59321</blrn><brmt>17GR0900FG344</brmt><bamnt>0</bamnt><bmsv>120,00</bmsv></contain></remittance>
Is there a way to get every node into variables so I can use them individual as variables in my form?
I want something like this
blrn = "032398106/17/59321"
brmt = "17GR0900FG344"
bamnt = "0"
bmsv = "120,00"
Itried a code like this
string data = "<remittance><contain><blrn>032398106/17/59321</blrn><brmt>lrn /afm check error</brmt><bamnt>0</bamnt><bmsv>0</bmsv></contain></remittance>";
var decoded = System.Web.HttpUtility.HtmlDecode(data);
string[] export;
export = decoded.Replace("<blrn>", "|").Split('|');
but it doesnt return the corect values to export
Upvotes: 2
Views: 58
Reputation: 7465
This text is essentially an Xml Document. You can get the content this way:
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.LoadXml(yourxmlstring);
System.Xml.XmlElement root = xd.DocumentElement;
System.Xml.XmlNodeList nl = root.SelectNodes("//remittance/contain");
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (System.Xml.XmlNode xnode in nl.Item(0).ChildNodes)
{
string name = xnode.Name;
string value = xnode.InnerText;
dictionary.Add(name, value);
}
Upvotes: 3