By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Best way to Sort an XmlDocument for display in a datagrid

P: n/a
bep
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 need a XmlDocument. So is there
an easy way to convert an XPathNavigator object to an XmlDocument?

And I could use a piece of Xstl to transform the doc. But this seems like a
lot of work. I would have to load the Xslt from file, cache it, and apply it.
I also have not found an easy way to transform an XmlDocument in memory. It
seems it is all aimed at taking a disk file, and applying the XSLT from a
file,a nf write to a file.

Thanks for any help.
David
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
for sorting you dont need to use XPathExpression.. its normally used to do a
scan and get nordes that match a certain criteria.
if you want to sort it.
Create a Dataset
Use XmlDataDocument (with relation to the dataset).
Load the XML Document or a part of it (if so load the schema first)
At this step the dataset is populated with the xml data.
now you can apply dataset.tables[0].Select(sortcriteria) to fetch the sorted
order of datarows that can be imported into a table clone and can be
displayed in the datagrid

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"be*@10.10.10.10" <be*@10.10.10.10@discussions.microsoft.com> wrote in
message news:C7**********************************@microsof t.com...
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 need a XmlDocument. So is there an easy way to convert an XPathNavigator object to an XmlDocument?

And I could use a piece of Xstl to transform the doc. But this seems like a lot of work. I would have to load the Xslt from file, cache it, and apply it. I also have not found an easy way to transform an XmlDocument in memory. It seems it is all aimed at taking a disk file, and applying the XSLT from a
file,a nf write to a file.

Thanks for any help.
David

Nov 18 '05 #2

P: n/a
bep
Thanks for your help

How do I get the XmlDataDocument into the Dataset?

Will this work without a schema? We get this data from another system, and
there is no Schema, I would have to create one.

This is also a lot of processing and memory usage. I am surprised XML
sorting is so hard to do...

Thanks again

"Hermit Dave" wrote:
for sorting you dont need to use XPathExpression.. its normally used to do a
scan and get nordes that match a certain criteria.
if you want to sort it.
Create a Dataset
Use XmlDataDocument (with relation to the dataset).
Load the XML Document or a part of it (if so load the schema first)
At this step the dataset is populated with the xml data.
now you can apply dataset.tables[0].Select(sortcriteria) to fetch the sorted
order of datarows that can be imported into a table clone and can be
displayed in the datagrid

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"be*@10.10.10.10" <be*@10.10.10.10@discussions.microsoft.com> wrote in
message news:C7**********************************@microsof t.com...
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 need a XmlDocument. So is

there
an easy way to convert an XPathNavigator object to an XmlDocument?

And I could use a piece of Xstl to transform the doc. But this seems like

a
lot of work. I would have to load the Xslt from file, cache it, and apply

it.
I also have not found an easy way to transform an XmlDocument in memory.

It
seems it is all aimed at taking a disk file, and applying the XSLT from a
file,a nf write to a file.

Thanks for any help.
David


Nov 18 '05 #3

P: n/a
i have just replied to another user with a complete example using xml, xsd
(for more info refer to post - Urgent help needed converting xmlnode to
dataset)

DataSet ds = new DataSet();
ds.ReadXmlSchema(@"..\..\Customers.xsd");

// create matching xml data document
XmlDataDocument xdd = new XmlDataDocument(ds);
try
{
xdd.Load(@"..\..\Customers.xml");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error Loading XML");
}
this.dgXML.DataSource = ds;
this.dgXML.DataMember = "CustomerData";

hope this helps

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"be*@10.10.10.10" <be*********@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
Thanks for your help

How do I get the XmlDataDocument into the Dataset?

Will this work without a schema? We get this data from another system, and
there is no Schema, I would have to create one.

This is also a lot of processing and memory usage. I am surprised XML
sorting is so hard to do...

Thanks again

"Hermit Dave" wrote:
for sorting you dont need to use XPathExpression.. its normally used to do a scan and get nordes that match a certain criteria.
if you want to sort it.
Create a Dataset
Use XmlDataDocument (with relation to the dataset).
Load the XML Document or a part of it (if so load the schema first)
At this step the dataset is populated with the xml data.
now you can apply dataset.tables[0].Select(sortcriteria) to fetch the sorted order of datarows that can be imported into a table clone and can be
displayed in the datagrid

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"be*@10.10.10.10" <be*@10.10.10.10@discussions.microsoft.com> wrote in
message news:C7**********************************@microsof t.com...
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 need a XmlDocument. So is

there
an easy way to convert an XPathNavigator object to an XmlDocument?

And I could use a piece of Xstl to transform the doc. But this seems like
a
lot of work. I would have to load the Xslt from file, cache it, and
apply it.
I also have not found an easy way to transform an XmlDocument in
memory. It
seems it is all aimed at taking a disk file, and applying the XSLT

from a file,a nf write to a file.

Thanks for any help.
David


Nov 18 '05 #4

P: n/a

"be*@10.10.10.10" <be*********@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
Thanks for your help

How do I get the XmlDataDocument into the Dataset?

Will this work without a schema? We get this data from another system, and
there is no Schema, I would have to create one.
DataSet.InferXMLSchema or just use the Schema designer in Visual Studio.

This is also a lot of processing and memory usage. I am surprised XML
sorting is so hard to do...


Not noticably more than applying a XLST transform.
David
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.