Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:13:48+00:00 2026-06-02T18:13:48+00:00

Most of the examples I’ve found on sorting an XML query do not include

  • 0

Most of the examples I’ve found on sorting an XML query do not include a namespace. Some of them do, but I’m not finding any example of performing a query and sorting when there is a namespace.

 <Search xmlns="http://whatever.whatever.com/gg/whatever">
 <BinSet Type="Category">
 <Bin>
  <BinName>Clothing</BinName>
  <BinItemCount>804</BinItemCount>
   <BinParameter>
    <Name>Category</Name>
    <Value>Women's Apparel</Value>
  </BinParameter>
</Bin>
 <Bin>
  <BinName>Tools</BinName>
  <BinItemCount>126</BinItemCount>
   <BinParameter>
    <Name>Category</Name>
    <Value>Tools, handtools and hardware</Value>
  </BinParameter>
</Bin>
</BinSet>
</Search>

I don’t have any control of the XML, so I have to deal with the namespace. Also, There are approximately 50 of these records in the XML and it is only part of a much larger XML file.

Dim nsuri as string = "http://whatever.whatever.com/gg/whatever"
Dim xpath as string = "dd:Search/dd:BinSet[Type="Category"]/*"
Dim nav As XPathNavigator = doc.CreateNavigator()
Dim exp As XPathExpression = nav.Compile(xpath)
Dim nsmgr As New XmlNamespaceManager(nav.NameTable)
nsmgr.AddNamespace("dd", nsuri)
exp.SetContext(nsmgr)

exp.AddSort("BinParameter/Value", XmlSortOrder.Ascending, XmlCaseOrder.UpperFirst, "en-US", XmlDataType.Text)

' now process in sorted order
Dim iterator As XPathNodeIterator = nav.Select(exp)
While iterator.MoveNext
    Dim nav2 As XPathNavigator = iterator.Current.Clone
    nav2.MoveToFirstChild()
    Debug.WriteLine(nav2.Value) 
End While

All of the examples I’ve seen show how to sort on the immediate child nodes, for example BinName or BinItemCount in my example XML. But I need all of this information and I need to sort on the BinParameter/Value node. I’ve tried every way I can think of…

One last thing to note, I don’t really care to use an XPathNodeIterator or XPathNavigator when all is said and done. Previously I was returning an XmlNodeList with all these records and my calling routine would traverse the nodelist to form links, like this:

<a href="mypage.aspx?si=Tools">Tools, handtools and hardware (126)</a>
<a href="mypage.aspx?si=Clothing">Women's Apparel (804)</a>

Does anyone know how to sort this XML by the nested child node “Value” using a namespace?

Also, would you know the quickest way to return the sorted results in an XmlNodeList or other .Net object so that I can have access to all of the values: BinName, BinItemCount, Name and Value? I’m not familiar with XPathNavigator or XPathNodeIterator.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:13:50+00:00Added an answer on June 2, 2026 at 6:13 pm

    Try setting the xpath variable to

    /dd:Sets/dd:Bin/dd:BinParameter
    

    and use the following AddSort line

    exp.AddSort("dd:Value", XmlSortOrder.Ascending, XmlCaseOrder.UpperFirst, "en-US", XmlDataType.Text)
    

    (note the dd: prefix to all elements)

    EDIT:

    Dim iterator As XPathNodeIterator = nav.Select(exp, nsmgr)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most examples I have found use Trace.WriteLineIf e.g. `Trace.WriteLineIf(mySwitch.TraceError,my error);' but using Trace.TraceError(my error);
In most examples that you find on the web when explicitly not using using,
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Most examples (if not all) that I see are the sort of a function
I've got a problem, and all articles or examples I found seem to not
In most examples I found on the Internet , I see something like this
I am new to directx, but have been surprised that most examples I have
I've started developing my first game. Here some my thoughts about architecture: Most examples
Most examples show how to redirect all subdomain traffic to a primary domain, maintaining
Most examples of creating remote branches involve pushing from a local branch Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.