473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Sort Xml using XpathExpression Addsort()

hi,

i have a xml file

<root>
<Type />
<Description />
<Category />
<employee >
<id>3</id>
</employee>
<employee>
<id>1</id>
</employee>
<employee>
<id>5</id>
</employee>
</root>

and i want output xml as
<root>
<Type />
<Description />
<Category />
<employee >
<id>1</id>
</employee>
<employee>
<id>3</id>
</employee>
<employee>
<id>5</id>
</employee>
</root>

that is i want updated xml to retain all the nodes(type,Description..)
and employee nodes sorted by their ids.

i am doing this with XpathExpression but with not with much suceess.
the XpathExpression Addsort() method isnt able to sort this.

Can anybody provide me the code on how to do this?
thanx
Vidit

Nov 12 '05 #1
4 4489
Hello!
that is i want updated xml to retain all the nodes(type,Description..)
and employee nodes sorted by their ids.

i am doing this with XpathExpression but with not with much suceess.
the XpathExpression Addsort() method isnt able to sort this.


AddSort sorts only the output, not the input.

You can't "edit" XML-Documents with XPath (I believe there will be an
editable XPathDocument in .NET 2.0 though).

As Martin Honnen said: use XSLT, it's the easiest way.

(untested)

....
<x:template match="/">
<root>
<x:for-each select="/root/employee">
<x:sort select="id" type="number" />
<x:copy-of select="node()" />
</x:for-each>
</root>
</x:template>
--
Pascal Schmitt
Nov 12 '05 #2
thanx for the reply

but i dont to use XSLT , i want to sort it through XpathExpression
AddSort()

Nov 12 '05 #3
vi*********@gmail.com wrote:
but i dont to use XSLT , i want to sort it through XpathExpression
AddSort()


XPath is a query language for selecting parts of XML document. You
cannot modify document using XPath. What you can whne using XmlDocument
is to select nodes with AddSort, insert them into document and then
remove existing ones.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
Nov 12 '05 #4
Hello!
but i dont to use XSLT , i want to sort it through XpathExpression
AddSort()


Well, that's not possible...

You can, as Oleg said, use the Expression to get a sorted List of Nodes.
Then you loop through that list, delete the contained nodes from the
Document and add them again - they will be in the correct order.
--
Pascal Schmitt
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DN | last post by:
I'd like to pass multiple attributes to XPath AddSort like: expr = nav.Compile(strQuery); expr.AddSort(sortArray, XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text); But I get...
1
by: viditmittal | last post by:
hi, i have a xml file <root> <Type /> <Description /> <Category /> <employee > <id>3</id>
1
by: rustyfancy | last post by:
I have a textBox that contains a string values. I need to take this string and use it as criteria for an XPath Expression. Here's what I have. Why isn't it working??? string s =...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
1
by: DN | last post by:
I'd like to pass multiple attributes to XPath AddSort like: expr = nav.Compile(strQuery); expr.AddSort(sortArray, XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text); But I get...
4
by: bep | last post by:
Hello What is the best way to sort an XmlDocument for display in a DataGrig? I can use Xpath with an XpathExpression, and a XpathNavigator. But this XpathNavigator object is of no use to me, I...
19
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I...
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
0
by: Chazam | last post by:
What I'm Trying to do is sort By Date. I came up whith the idea of splite the date in year, month and day then sort them individualy. this work perfect in xsl <xsl:sort order ="descending"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.