Its been a long time since my last post. I finally got something which I feel need to be posted else I will have a hard time finding it later.
Ok, one of my recent quests was how to remove duplicate nodes from an xml like below
Now if we want to transform this XML into another XML without the repeating
Transform this using XSLT
XmlDocument stripper = new XmlDocument();
stripper.Load(Server.MapPath("~/App_Data/transform.xsl")); //Compile here
StringWriter output = new StringWriter();
XslCompiledTransform emptyNodeRemover = new XslCompiledTransform();
emptyNodeRemover.Load(stripper); //Port output to string
output = new StringWriter();
XmlDocument source = new XmlDocument();
source.Load(Server.MapPath("~/App_Data/response.xml"));
emptyNodeRemover.Transform(new XmlNodeReader(source), null, output);
output.Flush(); //Reload source with emptied nodes
source.LoadXml(output.ToString());
The above xsl also specifies to restructure the xml file into
Now this transformed XML can be fed into a telerik RadGrid successfully as it is the format it accepts.
Cheers!
No comments:
Post a Comment