473,386 Members | 1,726 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.

sorting xml data in server control

I am passing an xml data file to a server control and need to sort the data. The data has three levels(tables).

What is the recommended approach to do the sorting ?

(using vb.net and asp.net 2.0)
Feb 21 '06 #1
4 1738

When I have to deal with alot of sorting.... I usually put everything in a
Strongly Typed DataSet.

If you have have control over the XML being sent... you can send it as
xml... to mimick the DataSet schema.

...

If not, you may have to do a Xml to Xml transformation .. to get the xml
formatted correctly.

MyStronglyTypedDataSet ds = new MyStrongTypedDataSet();

ds.//Code here to get your xml into the DataSet

ds.Select("", "LastName, FirstName, Age Desc");

the first parameter is the filter... which you set to empty string... the
second parameter is the sortby.

Look up the DataSet.Select command.

xsl sorting is pretty ... limited. so I don't chose that route anymore.


"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
I am passing an xml data file to a server control and need to sort the data. The data has three levels(tables).
What is the recommended approach to do the sorting ?

(using vb.net and asp.net 2.0)

Feb 21 '06 #2
are there any working examples of this somewhere ?
I can't find my way through all the steps to get this working.

I can get a dataset but it apparently isn't strongly typed, so the select isn't available

"sloan" <sl***@ipass.net> wrote in message news:ux**************@TK2MSFTNGP09.phx.gbl...

When I have to deal with alot of sorting.... I usually put everything in a
Strongly Typed DataSet.

If you have have control over the XML being sent... you can send it as
xml... to mimick the DataSet schema.

..

If not, you may have to do a Xml to Xml transformation .. to get the xml
formatted correctly.

MyStronglyTypedDataSet ds = new MyStrongTypedDataSet();

ds.//Code here to get your xml into the DataSet

ds.Select("", "LastName, FirstName, Age Desc");

the first parameter is the filter... which you set to empty string... the
second parameter is the sortby.

Look up the DataSet.Select command.

xsl sorting is pretty ... limited. so I don't chose that route anymore.


"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
I am passing an xml data file to a server control and need to sort the

data. The data has three levels(tables).

What is the recommended approach to do the sorting ?

(using vb.net and asp.net 2.0)


Feb 21 '06 #3
If you already have xml and you need to generate xml, xsl may be the
easiest route. Here's a sample xml file and the transform to sort by
order id, and by quantity.

(Data.xml)

<?xml version="1.0" encoding="utf-8" ?>
<orders>
<order id="789">
<items>
<item>
<name>paint</name>
<price>2</price>
<quantity>30</quantity>
</item>
<item>
<name>glue</name>
<price>10</price>
<quantity>2</quantity>
</item>
</items>
</order>
<order id="123">
<items>
<item>
<name>sprockets</name>
<price>1</price>
<quantity>50</quantity>
</item>
<item>
<name>cogs</name>
<price>20</price>
<quantity>5</quantity>
</item>
</items>
</order>
<order id="456">
<items>
<item>
<name>nails</name>
<price>2</price>
<quantity>100</quantity>
</item>
</items>
</order>
</orders>

(Sort.xsl)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="orders">
<orders>
<xsl:for-each select="order">
<xsl:sort data-type="number" select="@id" />
<order>
<xsl:attribute name="id">
<xsl:value-of select="@id"></xsl:value-of></xsl:attribute>
<xsl:apply-templates select="items" />
</order>
</xsl:for-each>
</orders>
</xsl:template>

<xsl:template match="items">
<xsl:for-each select="item">
<xsl:sort data-type="text" select="name" />
<item>
<name><xsl:value-of select="name"/></name>
<price><xsl:value-of select="price" /></price>
<quantity><xsl:value-of select="quantity" /></quantity>
</item>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

You can use an XSLCompiledTransform to do the sort, like this (sorry
for the C#):

static void Main(string[] args)
{
XmlTextReader xmlSource = new XmlTextReader("Data.xml");
XPathDocument xpathDoc = new XPathDocument(xmlSource);

XmlTextReader xslSource = new XmlTextReader("Sort.xsl");
XslCompiledTransform xsltDoc = new XslCompiledTransform();
xsltDoc.Load(xslSource);

StringBuilder sb = new StringBuilder();
TextWriter tw = new StringWriter(sb);

xsltDoc.Transform(xpathDoc, null, tw);

Console.WriteLine(sb.ToString());

Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}

If you have other differences between your source and destination
schema you can transform it in this step too.

-Carl

Feb 21 '06 #4
thanks, this solved my problem.
Feb 22 '06 #5

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

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: Alan Searle | last post by:
I find that I can display structured data very nicely using XML with an XSL template. As an extra 'goodie', I would like to give users the ability to sort that data (for example with a button...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
2
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
0
by: Simon Gregory | last post by:
I am currently attempting to figure out how the new databinding stucture works in ASP.NET 2.0 after working with v1.0 & v1.1 for several years. It seems that if you wish to do set up databinding...
0
by: Dorte | last post by:
Hi, I use the gridview control to display data. I use a dataadapter to fill a datatable from an SQL server - the command is a stored procedure. Furthermore I have a couple of template columns...
1
by: dorandoran | last post by:
The sort on the childgrid is not working; nothing happens when I click on the each column header for sort. (I followed Satay's sample: http://www.codeproject.com/KB/aspnet/EditNestedGridView.aspx)...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.