473,383 Members | 1,891 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,383 software developers and data experts.

How to sort a XML file??

I heard of importing your xml doc into a dataset, then sort the
dataset and re-populate your xml, but I'm not sure how to code this or
is there another way of sorting a XML file? I not familiar with
Dataset coding and how that would work.
Here is my XML file:

?xml version="1.0"?>
<IndividualListing>
<Individual>
<Name>Aaron, Scott</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Boston, Jeff</Name>
<Pager>61********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Adams, Ryan</Name>
<Pager>21********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Thomas, Naveed</Name>
<Pager>61********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Baker, Srinivas</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Wilson, Don</Name>
<Pager>84********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Naveed Reddy</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Sanders, William</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Anderson, Karl R.</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>
</IndividualListing>
thanks

Apr 23 '07 #1
2 7429
ri***********@northwesternmutual.com wrote:
I heard of importing your xml doc into a dataset, then sort the
dataset and re-populate your xml, but I'm not sure how to code this or
is there another way of sorting a XML file? I not familiar with
Dataset coding and how that would work.
Here is my XML file:

?xml version="1.0"?>
<IndividualListing>
<Individual>
<Name>Aaron, Scott</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>
Here is an XSLT stylesheet that sorts your Individual elements on the
Name child elements:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="IndividualListing">
<xsl:copy>
<xsl:apply-templates select="Individual">
<xsl:sort select="Name" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Result then starts like this

<IndividualListing>
<Individual>
<Name>Aaron, Scott</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Adams, Ryan</Name>
<Pager>21********@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Anderson, Karl R.</Name>
<Pager>31********@archwireless.net</Pager>
</Individual>

You can run XSLT stylesheets from inside Visual Studio 2005 or with .NET
code where you use System.Xml.Xsl.XslCompiledTransform with .NET 2.0.

See
<http://msdn2.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx>
VB.NET example is as easy as

Dim xslt As New XslCompiledTransform()
xslt.Load("stylesheet.xsl")

' Execute the transform and output the results to a file.
xslt.Transform("file.xml", "sorted.xml")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #2
If I were you.. I would keep your DATA in a DATABASE and screw XML in
the nose

On Apr 23, 5:18 am, Martin Honnen <mahotr...@yahoo.dewrote:
richardkre...@northwesternmutual.com wrote:
I heard of importing your xml doc into a dataset, then sort the
dataset and re-populate your xml, but I'm not sure how to code this or
is there another way of sorting a XML file? I not familiar with
Dataset coding and how that would work.
Here is my XML file:
?xml version="1.0"?>
<IndividualListing>
<Individual>
<Name>Aaron, Scott</Name>
<Pager>3122220...@archwireless.net</Pager>
</Individual>

Here is an XSLT stylesheet that sorts your Individual elements on the
Name child elements:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="IndividualListing">
<xsl:copy>
<xsl:apply-templates select="Individual">
<xsl:sort select="Name" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Result then starts like this

<IndividualListing>
<Individual>
<Name>Aaron, Scott</Name>
<Pager>3122220...@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Adams, Ryan</Name>
<Pager>2129410...@archwireless.net</Pager>
</Individual>
<Individual>
<Name>Anderson, Karl R.</Name>
<Pager>3122051...@archwireless.net</Pager>
</Individual>

You can run XSLT stylesheets from inside Visual Studio 2005 or with .NET
code where you use System.Xml.Xsl.XslCompiledTransform with .NET 2.0.

See
<http://msdn2.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtr...>
VB.NET example is as easy as

Dim xslt As New XslCompiledTransform()
xslt.Load("stylesheet.xsl")

' Execute the transform and output the results to a file.
xslt.Transform("file.xml", "sorted.xml")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Apr 23 '07 #3

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

Similar topics

11
by: krunkelgarten | last post by:
Allright, thank you guys!! I got it going. Now i have another question; Is there a way to link a date to a persons name, so i can get the pop-up, and the pop-up then automatically grabs the...
1
by: VMI | last post by:
I have a Windows datagrid whose column values are (1,10,100,1000,101,10-1,103,11,1710,2). When the column's sorted (the column's of type String), it'll sort this way , which is wrong. But in...
0
by: Mark | last post by:
I would like to sort the contents of an ASCII file based on one or more fields. How is this implemented in VB.Net? The file could have more than a milliion lines, so performance of the sort is...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
23
by: r.e.s. | last post by:
I have a million-line text file with 100 characters per line, and simply need to determine how many of the lines are distinct. On my PC, this little program just goes to never-never land: def...
9
by: incredible | last post by:
how to sort link list of string
25
by: Subra | last post by:
Hi, What is the best way to find the 1000 largest numbers from the file having hell lot of entries ? Can you please help me to find out the way ? Do I need to go for B+ trees ?? Please help,...
5
by: dh87lfc | last post by:
Hi, I have almost got my script to do what I want it to do, but I have one final problem for which I have been searching for a solution. My code now successfully reads the content of every text file...
4
by: Tobiah | last post by:
I have a list of objects that generate code. Some of them depend on others being listed first, to satisfy dependencies of others. I wrote a cmp function something like this: def dep_cmp(ob1,...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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: 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...

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.