Veggies
New member
- Joined
- Jul 3, 2022
- Messages
- 3
- Programming Experience
- 5-10
I have Tried to remove all the attributes from XML but getting some errors please help me to achieve my result.
desire output:
C sharp code:
var strData=@"
<data>
<emp_details id="5" grade="z0234-o0948-45op-0002">
<name>Randee Mozos</name>
<salary include="unpaid">345643</salary>
</emp_details>
<emp_details id="23" grade="z0124-o0921-41ds-0451">
<name>Nirzosha</name>
<salary include="unpaid" leave="accept">453011</salary>
</emp_details>
</data>
";
foreach (XmlNode xmlNode in doc.SelectNodes("//ENVELOPE"))
{
RemoveAttributes(xmlNode);//error
response = JsonConvert.SerializeObject(xmlNode);
_xmlREsponseList.Add(response);
}
private void RemoveAttributes(XmlNode node)
{
string strType = node.NodeType.ToString();
if (strType == "Element")
{
node.Attributes.RemoveAll();
}
if (node.HasChildNodes)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
RemoveAttributes(node.ChildNodes[i]);
}
}
}
desire output:
C#:
{
"data": {
"emp_details": [
{
"name": "Randee Mozos",
"salary": 345643
},
{
"name": "Nirzosha",
"salary": 453011
}
]
}
}
Last edited by a moderator: