I am attempting to write some C# code that will parse an XML based on my conditions and certain tags. I have utilized XPATH to find the specific nodes and put them in a NodeList, however I will also have to create some code that will avoid copying down more than one element/tag for each entity. I will then takes this new Lists and create a new nodes/XML doc based on the values I've got.
Although the XML I am parsing is much more messy and larger than this, for Example, I would only want to find the 1st Year and 1st Brand of each cleat, thus making years captured: 2004 & 2010 and Brands: Adidas & Nike.
It is possible to achieve this? I've read some references towards XSLT, but doesn't that only do html/website displays?
Thank You in advance
Thank You in advance
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
FrancisPosted Apr 30, 2010, 10:34 AM
Thank You again
Jaish MathewsPosted Apr 29, 2010, 2:45 PM
Why can't use custom logic to remove dulicate items like below
XmlDocument doc = new XmlDocument();
doc.Load(@"D:\PERSONAL\ConsoleApplication1\XMLFile1.xml");
XmlNodeList list= doc.GetElementsByTagName("Cleat");
foreach(XmlNode node in list)
{
foreach (XmlNode childNode in node.ChildNodes)
{
if ((childNode.NextSibling != null) && (childNode.NextSibling.Name.Equals(childNode.Name)))
{
XmlNode duplicate = childNode.NextSibling;
node.RemoveChild(duplicate);
}
}
}
NB:After above lines execution, Check doc.InnerXml to confirm