Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Bind/Parse from XmlNode to a data grid
 

Bind/Parse from XmlNode to a data grid

Hi i'm using XmlNode to retreive the GetListItems of a sharepoint List in an XML.
The xml is ok but when i'm connecting to the reader it is being null
Here is my code

try

   {

      System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

      XmlNode ndListItems = service.GetListItems(listName, viewName, null, null, rowLimit, null, null);

      MessageBox.Show(ndListItems.OuterXml);



      XmlNodeReader reader = new XmlNodeReader(ndListItems);

      DataSet ds = new DataSet();

      ds.ReadXmlSchema(reader);

      ds.ReadXml(reader);

      dataGridView1.DataSource = ds.Tables[0];

  }

Any help or suggestions please
Thanks
Keyaa
keyaa  Tuesday, September 29, 2009 9:36 AM

Hi keyaa,

You said: The xml is ok but when i'm connecting to the reader it is being null.

Do you mean the xml content of the XmlNode ndListItems is OK, but when you create a XmlNodeReader from the XmlNode, the reader is null?

From my experience, the code below would throw some exception:
    ds.ReadXmlSchema(reader);

This is because the XmlNodeReader can only read the xml content, not the xml schema. So this line of code would not work correctly. You need to remove this line of code. You can get more about XmlNodeReader from:
http://msdn.microsoft.com/en-us/library/system.xml.xmlnodereader.aspx
Please read the remarks.

I also suggest that you can move the code from the client to the server and return the DataSet directly in the web method.

Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, October 05, 2009 6:01 AM
Hi Aland

Thanks very much with this informtion. I have read the remarks and i am working with 2.0 Framework. so i used the XmlReder instead of XmlNodeReader. This is my new code. Do you think is good?

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                XmlNode ndListItems = service.GetListItems(listName, viewName, null, null, rowLimit, null, null);
                MessageBox.Show(ndListItems.OuterXml);

               
                XmlReader reader1 = new XmlNodeReader(ndListItems);
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ConformanceLevel = ConformanceLevel.Fragment;
                settings.IgnoreWhitespace = true;
                settings.IgnoreComments = true;
                XmlReader reader = XmlReader.Create(reader1, settings);

                DataSet ds = new DataSet();

                //ds.ReadXmlSchema(reader);

                ds.ReadXml(reader);

                dataGridView1.DataSource = ds.Tables[0];

                dataGridView1.Show();

 and it throws this exception on this line:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

XmlReader reader = XmlReader.Create(reader1, settings);
I have made the reader1 as parameter because i don't want to save the xml i want to read directly trough the xml.

Thanks in advice for your help

Keyaa
keyaa  Monday, October 05, 2009 7:25 AM
Hi keyaa,

Could you please provide the message and detail information about the exception. I need those to figure out the cause of the issue accurately. You also need to test the code only in the server endpoint to test if the code works fine on the server machine. Please tell me the test results. Thanks.

You can follow the link below and search InvalidOperationException, you would find some causes of this exception:
http://msdn.microsoft.com/en-us/library/x1h1125x.aspx.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, October 07, 2009 2:01 AM

You can use google to search for other answers

Custom Search

More Threads

• Mouse coordinates in CellMouseClick event
• Check Box in a Combo Box
• Auto commit in sql server off
• Making a DataGrid Editable
• Format columns in the .NET Winforms Datagrid
• DataGridView twice as slow in Final Release compared to Beta 2
• Help with Access data binding
• System.Data.ConstraintException
• Navigating With DataGridView - What Is The Current Record?
• Master/detail drag and drop problem.