Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sander Houttekier 114 posts 163 karma points
    Sep 01, 2009 @ 19:19
    Sander Houttekier
    0

    sorting content of a xpathnodeiterator returned by getXmlNodeByXPath...

    hi, when working with xml documents, i am used to creating a navigator, and applying  sort on it trough an xpathExpression in c#

    but the umbraco library function getXmlNodeByXpath returns an iterator already, is there a way to sort this return value?

    best regards

    Sander

  • Ron Brouwer 273 posts 768 karma points
    Sep 01, 2009 @ 19:29
    Ron Brouwer
    0

    Have you tried <xsl:sort> http://www.w3schools.com/xsl/el_sort.asp

     

  • Sander Houttekier 114 posts 163 karma points
    Sep 01, 2009 @ 19:33
    Sander Houttekier
    0

    Ron, this is in .net C#,  this is not sorting in xslt sorry for the confusion

    but at this point i have come to believe it is not possible to sort an iterator except for putting it all into new sortable structure by going over every item in the iterator...

  • Ron Brouwer 273 posts 768 karma points
    Sep 01, 2009 @ 19:36
    Ron Brouwer
    0

    Have you considdered using linq to xml?

  • Ron Brouwer 273 posts 768 karma points
    Sep 01, 2009 @ 19:41
    Ron Brouwer
    0

    http://mstanciu.blogspot.com/2008/08/sorting-elements-in-xml-document.html

    When using C# I always prefer to use Linq to Xml

    You can load the contents of your iterator using XDocument.Parse(

  • Sander Houttekier 114 posts 163 karma points
    Sep 01, 2009 @ 19:56
    Sander Houttekier
    0

    i will give it a shot first thing in the morning, or maybe if i find some time tonight.

    thanks for the input and i'll get back to this post after trying it out.

  • Sander Houttekier 114 posts 163 karma points
    Sep 01, 2009 @ 20:16
    Sander Houttekier
    0

    i'm back quicker than i tought,

    2 remarks:

    1. the way i see it in the article, i still need to go over my iterator to pump the xml back into an xdocument in order to sort it with the linq functionality
    2. and secondly, but probably more difficult to ignore, the site runs in a 2.0 environement. this technique will probably only work on 3.5.
  • Ron Brouwer 273 posts 768 karma points
    Sep 02, 2009 @ 09:29
    Ron Brouwer
    0

    You can use:

    var myDoc = XDocument.Parse(myNavigator.OuterXml.ToString())

    If you can't install 3.5 this technique is useless indeed.

    Some other code you can use instead of getXmlNodeByXpath :

    XPathNavigator navigator = content.Instance.XmlContent.CreateNavigator();

    navigator.Select(navigator.Compile(".....").AddSort(....));

    Ron

Please Sign in or register to post replies

Write your reply to:

Draft