Best way to Sort an XmlDocument for display in a datagrid

G

Guest

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
 
H

Hermit Dave

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)
 
G

Guest

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 said:
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)
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
 
H

Hermit Dave

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)
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 said:
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)
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
 
D

David Browne

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top