Im trying to do an add sort for an XML file for a document system, including a date modified entry.
Basically I have a gridview to display the XML of all the document list, and I’m running addsort on the data just before displaying.
Each file has a tag, with a true or false, and then a published date (these are complete documents and therefore need no modification), when a document has been modified the tag gets changed to true, once its been finished it’s given a published date on the tag.
To have the correct order for what the customer needs is those Modified->Ones with a modified date->those with a false modified tag.
Currently I have for sorting by title:
StringReader str = new StringReader(PLCDocsXML.InnerXml);
XPathDocument doc = new XPathDocument(str);
XPathNavigator navigator2 = PLCDocsXML.CreateNavigator();
XPathExpression subselectExpression = navigator2.Compile(XpathExpr);
if (asc)
{
subselectExpression.AddSort("title", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text);
}
The XML Looks like this:
<result>
<document>
<title>Title</title>
<otherstuff />
<modified>[true/false]<modified> #those with true first before false
<publishdate /> #if not got a publish date
<publishdate>2009-10-16</publishDate>
</document>
</result>
So the order I need is:
<result>
<document>
<title>Title1</title>
<otherstuff />
<modified>true<modified>
<publishdate />
</document>
<document>
<title>Title4</title>
<otherstuff />
<modified>true<modified>
<publishdate>2010-11-27</publishDate>
</document>
<document>
<title>Title2</title>
<otherstuff />
<modified>true<modified>
<publishdate>2009-10-16</publishDate>
</document>
<document>
<title>Title3</title>
<otherstuff />
<modified>false<modified>
<publishdate />
</document>
</result>
Thanks for any help you can give
I ended up fixing this myself (I couldn’t get kirills to compile, it was complaining that there was no concat method)
The way was to use an xpath select to separate out all the different types of item and then sort each of them induvidually before iterating over them as if they were a single item, worked for me