I need to read an xml file tag which has colon in it and bind it into model class
My xml file
<?xml version="1.0" encoding="utf-8"?>
<feed xml:base=""
xmlns=""
xmlns:d=""
xmlns:m="">
<id>my url</id>
<title type="text">ItemList</title>
<updated>2019-05-07T14:18:08Z</updated>
<link rel="self" title="ItemList" href="ItemList" />
<entry m:etag="">
<id></id>
<category term="NAV.ItemList" scheme="" />
<link rel="edit" title="ItemList" href="" />
<title />
<updated>2019-05-07T14:18:08Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:No>LSU-458</d:No>
<d:Description>speaker</d:Description>
<d:Type>Inventory</d:Type>
</m:properties>
</content>
</entry>
</feed>
My c# code
List<CustomerModel> customers = new List<CustomerModel>();
doc.Load(Server.MapPath("~/oWtMRUR8_.xml"));
foreach (XmlNode node in
doc.SelectNodes("/feed/id/title/updated/link/mproperties"))
{
customers.Add(new CustomerModel
{
No = int.Parse(node["d:No"].InnerText),
Description = node["d:Description"].InnerText,
Type = node["d:Type"].InnerText
});
}
return View(customers);
I need to bind only the d:no,d:description,d:type in my model class using foreach loop,these tags are with colon so I am not able to extract the contents in the tag and namespace was mentioned as an option(but didn't worked). I am new to this and can't able to find the right method, hope anyone helps.
My expected result:
No =LSU-458 ,
Description = speaker,
Type = Inventory
Firstly, the XML is not valid, the namespace declarations need a name, for example
Then you can loop through the
propertieslike this:And finally, you cannot
int.Parse()thed:Nobecause it's a string.