| Re: |
web mavin provided a rated reply to madhu radha on Saturday, November 07, 2009 1:50 AM |
|
You could sort it using XSL and XslCompiledTransform. So, you could have an approach something like this:
- Write an xsl that matches your xml, sorts them and had the sorted list as output
- Get the XslCompiledTransform holding that xsl from cache, and if it doesn't exist, create it and insert into cache
- Transform your xml through your xsl into a new XmlDocument
Also, check this link for more info. |
| Reply Reply Using Power Editor |
| |
| |
Rank |
Winnings |
Points |
| November |
8 |
$22.00 |
56 |
| October |
7 |
$38.00 |
131 |
|
|
|
|
|
|
| re |
Web star provided a rated reply to madhu radha on Saturday, November 07, 2009 11:33 AM |
|
Code:
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"Input.xml");
XmlDocument xmlDocCopy = new XmlDocument(); xmlDocCopy.LoadXml(xmlDoc.OuterXml); xmlDocCopy.SelectSingleNode("//Links").RemoveAll();
XmlNode node = xmlDoc.SelectSingleNode("//Links"); XPathNavigator navigator = node.CreateNavigator(); XPathExpression selectExpression = navigator.Compile("Link/Title"); selectExpression.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text); XPathNodeIterator nodeIterator = navigator.Select(selectExpression); while (nodeIterator.MoveNext()) { XmlNode linkNode = xmlDoc.SelectSingleNode("//Link[Title=\"" + nodeIterator.Current.Value + "\"]"); XmlNode importedLinkNode = xmlDocCopy.ImportNode(linkNode, true); xmlDocCopy.SelectSingleNode("//Links").AppendChild(importedLinkNode); }
xmlDocCopy.Save(@"Output.xml");
|
| Reply Reply Using Power Editor |
| |
| |
Rank |
Winnings |
Points |
| November |
5 |
$55.00 |
143 |
| October |
10 |
$28.00 |
94 |
|
|
|
|
|
|
| Yes, Web Mavin is right. |
[)ia6l0 iii provided a rated reply to madhu radha on Sunday, November 08, 2009 1:43 PM |
|
The approach seems to be well thought of in terms of execution.
Also worth having a look is the usefulness of XSL to sort and filter the data. Charlie Heinemann has written an article on this about a decade back and you can view it here.
|
| Reply Reply Using Power Editor |
| |
| |
Rank |
Winnings |
Points |
| November |
1 |
$217.00 |
560 |
| October |
1 |
$226.00 |
771 |
|
|
|
|
|
|
| doubt |
| madhu radha replied to Web star on Saturday, November 14, 2009 2:25 AM |
|
hi,
u prefered this code for sorting of data in xml document.actually i dont know wat is navigator add y we useed navigator.compile in which situations we can use them.
Code:
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"Input.xml");
XmlDocument xmlDocCopy = new XmlDocument(); xmlDocCopy.LoadXml(xmlDoc.OuterXml); xmlDocCopy.SelectSingleNode("//Links").RemoveAll();
XmlNode node = xmlDoc.SelectSingleNode("//Links"); XPathNavigator navigator = node.CreateNavigator(); XPathExpression selectExpression = navigator.Compile("Link/Title"); selectExpression.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text); XPathNodeIterator nodeIterator = navigator.Select(selectExpression); while (nodeIterator.MoveNext()) { XmlNode linkNode = xmlDoc.SelectSingleNode("//Link[Title=\"" + nodeIterator.Current.Value + "\"]"); XmlNode importedLinkNode = xmlDocCopy.ImportNode(linkNode, true); xmlDocCopy.SelectSingleNode("//Links").AppendChild(importedLinkNode); }
xmlDocCopy.Save(@"Output.xml");
|
| Reply Reply Using Power Editor |
| |
| |
Rank |
Winnings |
Points |
| November |
0 |
$0.00 |
0 |
| October |
0 |
$0.00 |
0 |
|
|
|
|
|
|
| doubt |
| madhu radha replied to Web star on Saturday, November 14, 2009 2:25 AM |
|
hi,
u prefered this code for sorting of data in xml document.actually i dont know wat is navigator add y we useed navigator.compile in which situations we can use them.
Code:
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"Input.xml");
XmlDocument xmlDocCopy = new XmlDocument(); xmlDocCopy.LoadXml(xmlDoc.OuterXml); xmlDocCopy.SelectSingleNode("//Links").RemoveAll();
XmlNode node = xmlDoc.SelectSingleNode("//Links"); XPathNavigator navigator = node.CreateNavigator(); XPathExpression selectExpression = navigator.Compile("Link/Title"); selectExpression.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text); XPathNodeIterator nodeIterator = navigator.Select(selectExpression); while (nodeIterator.MoveNext()) { XmlNode linkNode = xmlDoc.SelectSingleNode("//Link[Title=\"" + nodeIterator.Current.Value + "\"]"); XmlNode importedLinkNode = xmlDocCopy.ImportNode(linkNode, true); xmlDocCopy.SelectSingleNode("//Links").AppendChild(importedLinkNode); }
xmlDocCopy.Save(@"Output.xml");
|
| Reply Reply Using Power Editor |
| |
| |
Rank |
Winnings |
Points |
| November |
0 |
$0.00 |
0 |
| October |
0 |
$0.00 |
0 |
|
|
|
|
|
|
|