Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / April 2007

Tip: Looking for answers? Try searching our database.

How to sort a XML file??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
richardkreidl@northwesternmutual.com - 23 Apr 2007 12:32 GMT
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>3122220365@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Boston, Jeff</Name>
   <Pager>6152257514@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Adams, Ryan</Name>
   <Pager>2129410781@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Thomas, Naveed</Name>
   <Pager>6159416077@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Baker, Srinivas</Name>
   <Pager>3122010073@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Wilson, Don</Name>
   <Pager>8472222016@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Naveed Reddy</Name>
   <Pager>3122225858@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Sanders, William</Name>
   <Pager>3122224506@archwireless.net</Pager>
 </Individual>
 <Individual>
   <Name>Anderson, Karl R.</Name>
   <Pager>3122051023@archwireless.net</Pager>
 </Individual>
</IndividualListing>

thanks
Martin Honnen - 23 Apr 2007 13:18 GMT
> 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
[quoted text clipped - 8 lines]
>     <Pager>3122220365@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>3122220365@archwireless.net</Pager>
  </Individual>
  <Individual>
    <Name>Adams, Ryan</Name>
    <Pager>2129410781@archwireless.net</Pager>
  </Individual>
  <Individual>
    <Name>Anderson, Karl R.</Name>
    <Pager>3122051023@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")

Signature

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

Susie DBA [MSFT] - 23 Apr 2007 20:07 GMT
If I were you.. I would keep your DATA in a DATABASE and screw XML in
the nose

> richardkre...@northwesternmutual.com wrote:
> > I heard of importing your xml doc into a dataset, then sort the
[quoted text clipped - 64 lines]
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.