Sort an XML document using DataView

Discussion in 'ASP .Net' started by =?Utf-8?B?RWQgQ2hpdQ==?=, Dec 14, 2004.

  1. Hi,

    I am tring to use DataView Sort ability to sort an XML document, here are my
    code snippet:

    ds1.ReadXml("c:\temp\catalog1.xml")
    ds1.Tables(0).DefaultView.Sort = "ProdName"
    ds1.WriteXml("c:\temp\catalog2.xml")

    Does not work at all, can someone help?

    TIA
     
    =?Utf-8?B?RWQgQ2hpdQ==?=, Dec 14, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?RWQgQ2hpdQ==?=

    Scott Allen Guest

    The Sort property only applies if you look at the table through a
    DataView (the DefaultView in this case). Since a DataView doesn't have
    a WriteXml method, you'd have to hand craft the code to write the XML
    out in specific order (perhaps by looping through the records as
    sorted by DefaultView).

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Tue, 14 Dec 2004 11:19:04 -0800, "Ed Chiu"
    <> wrote:

    >Hi,
    >
    >I am tring to use DataView Sort ability to sort an XML document, here are my
    >code snippet:
    >
    > ds1.ReadXml("c:\temp\catalog1.xml")
    > ds1.Tables(0).DefaultView.Sort = "ProdName"
    > ds1.WriteXml("c:\temp\catalog2.xml")
    >
    >Does not work at all, can someone help?
    >
    >TIA
    >
    >
     
    Scott Allen, Dec 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Denzil

    Query on DataView.Sort Property

    Denzil, Oct 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,263
    Chris Taylor
    Oct 23, 2003
  2. nish
    Replies:
    3
    Views:
    1,600
    Gopal \(FMS, Inc.\)
    Feb 2, 2005
  3. Tony Prichard
    Replies:
    0
    Views:
    746
    Tony Prichard
    Dec 12, 2003
  4. CodeMonkey
    Replies:
    1
    Views:
    733
    joyal jhaveri
    Feb 4, 2011
  5. Navin
    Replies:
    1
    Views:
    710
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page