Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML round trip problems

XML round trip problems

Scheduled Pinned Locked Moved XML / XSL
xmlhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    james cxx
    wrote on last edited by
    #1

    I'm writing out a dataset... dsPrefs.WriteXml(ManagerPrefsFilename, XmlWriteMode.WriteSchema); and, at other times reading it in... dsPrefs.ReadXml(ManagerPrefsFilename,XmlReadMode.IgnoreSchema); The problem is that one of the columns is of type Point. The XML written by .WriteXml seems to contain all the info needed to describe this. Yet when I read it back in with .ReadXml and check the type it is System.String. I've tried different XmlReadMode to no avail. Any idea why these aren't being converted to the correct type when read in? -- James --

    C 1 Reply Last reply
    0
    • J james cxx

      I'm writing out a dataset... dsPrefs.WriteXml(ManagerPrefsFilename, XmlWriteMode.WriteSchema); and, at other times reading it in... dsPrefs.ReadXml(ManagerPrefsFilename,XmlReadMode.IgnoreSchema); The problem is that one of the columns is of type Point. The XML written by .WriteXml seems to contain all the info needed to describe this. Yet when I read it back in with .ReadXml and check the type it is System.String. I've tried different XmlReadMode to no avail. Any idea why these aren't being converted to the correct type when read in? -- James --

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Because you're ignoring the schema ? Does the XML mark the variable as being of type point, with an attribute or something ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      J 1 Reply Last reply
      0
      • C Christian Graus

        Because you're ignoring the schema ? Does the XML mark the variable as being of type point, with an attribute or something ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        J Offline
        J Offline
        james cxx
        wrote on last edited by
        #3

        Here's a simplified example. It creates an Xml file named "XmlRoundTrip.xml" on the Desktop from a DataSet and then Reads it back in. Just add the code below to the constructor of a default Form template and run it. The first Message box shows "Type written: System.Drawing.Point". The dataset is then cleared and the data is re-read. But the second Message box shows "Type read: System.String". Any ideas? Am I expecting too much from the DS XML methods? // Create a DataSet DataSet ds = new DataSet("MyDataSet"); // Create a Table for the DataSet DataTable dt = ds.Tables.Add("MyDataTable"); // Definte two columns for the DataTable DataColumn dcA = new DataColumn("PointColumn", typeof(Point)); dcA.DefaultValue = new Point(8, 13); DataColumn dcB = new DataColumn("SizeColumn", typeof(Size)); dcB.DefaultValue = new Size(21, 34); // Add the columns to the DataDable dt.Columns.Add(dcA); dt.Columns.Add(dcB); // Create a new row with default values and add it to the table DataRow dr = dt.NewRow(); dt.Rows.Add(dr); // Build file name for Xml file. string myTempFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); string myXmlFilename = myTempFolder + "\\XmlRoundTrip.xml"; // Write the Xml file. ds.WriteXml(myXmlFilename, XmlWriteMode.WriteSchema); // Confirm the type of the first column. MessageBox.Show("Type written: " + dt.Rows[0]["PointColumn"].GetType().ToString()); // Clear the table dt.Clear(); // Read the data from the Xml file. ds.ReadXml(myXmlFilename, XmlReadMode.ReadSchema); // Inspect read type. MessageBox.Show("Type read: " + dt.Rows[0]["PointColumn"].GetType().ToString()); -- James --

        C 1 Reply Last reply
        0
        • J james cxx

          Here's a simplified example. It creates an Xml file named "XmlRoundTrip.xml" on the Desktop from a DataSet and then Reads it back in. Just add the code below to the constructor of a default Form template and run it. The first Message box shows "Type written: System.Drawing.Point". The dataset is then cleared and the data is re-read. But the second Message box shows "Type read: System.String". Any ideas? Am I expecting too much from the DS XML methods? // Create a DataSet DataSet ds = new DataSet("MyDataSet"); // Create a Table for the DataSet DataTable dt = ds.Tables.Add("MyDataTable"); // Definte two columns for the DataTable DataColumn dcA = new DataColumn("PointColumn", typeof(Point)); dcA.DefaultValue = new Point(8, 13); DataColumn dcB = new DataColumn("SizeColumn", typeof(Size)); dcB.DefaultValue = new Size(21, 34); // Add the columns to the DataDable dt.Columns.Add(dcA); dt.Columns.Add(dcB); // Create a new row with default values and add it to the table DataRow dr = dt.NewRow(); dt.Rows.Add(dr); // Build file name for Xml file. string myTempFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); string myXmlFilename = myTempFolder + "\\XmlRoundTrip.xml"; // Write the Xml file. ds.WriteXml(myXmlFilename, XmlWriteMode.WriteSchema); // Confirm the type of the first column. MessageBox.Show("Type written: " + dt.Rows[0]["PointColumn"].GetType().ToString()); // Clear the table dt.Clear(); // Read the data from the Xml file. ds.ReadXml(myXmlFilename, XmlReadMode.ReadSchema); // Inspect read type. MessageBox.Show("Type read: " + dt.Rows[0]["PointColumn"].GetType().ToString()); -- James --

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Good point - the XML generated is bursting with type information, so there's no reason I can see for this not to work, but it doesn't. How pathetic. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups