locked
datatable.writexml boolean hashcode? RRS feed

  • Question

  • I need to export my dataset (from access database) to xml

    I have used datatable.writexml which writes the xml files successfully

    however, for boolean type (or "Yes/No" type) columns inside my access database, writexml writes them as

    <ShowInfo>true</ShowInfo>

    but wat I need is the hashcode which is something like

    <ShowInfo>1</ShowInfo>

    It's interesting that when I use the "export XML" option inside access, it writes the hashcode "1" instead of "true"

    is there any way to implement this feature?

    please note that for my current task, I'm not allowed to change the database table column, so "ShowInfo" still has to be a "Yes/No"

    but I need write 1/0 instead of true/false

    Cheers

     

     

    Sunday, May 30, 2010 11:25 PM

Answers

  • Hi,

    As I learnt from your post,  you are trying to change some elements when you call the WriteXml method, I'm afraid this method does not provide this kind of control that you would have if the data were stored in custom classes when we serialize a class. (Alternatively, we can serialize a dataset)

    I'd suggest you read the output xml file into a xmldocument and replace these "Yes/No" with "1/0".

    Here is an article about manipulating XML data with XPath and XmlDocument:
     http://www.codeproject.com/KB/cpp/myXPath.aspx

    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Harry Zhu Wednesday, June 9, 2010 7:57 AM
    Thursday, June 3, 2010 1:27 AM

All replies

  • You can add new column and set expression in that column which output result to 1 or 0. 

    like below 

          DataColumn test = new DataColumn("test");
          test.DataType = System.Type.GetType("System.Int32");
          test.Expression = "IIF(BooleanCol=true,1,0)";
          myTable.Columns.Add(test);


    Nayan Paregi | Microsoft Certified Technology Specialist (MCTS)
    • Proposed as answer by Nayan Paregi Wednesday, June 2, 2010 3:03 AM
    Tuesday, June 1, 2010 3:11 AM
  • Hi,

    As I learnt from your post,  you are trying to change some elements when you call the WriteXml method, I'm afraid this method does not provide this kind of control that you would have if the data were stored in custom classes when we serialize a class. (Alternatively, we can serialize a dataset)

    I'd suggest you read the output xml file into a xmldocument and replace these "Yes/No" with "1/0".

    Here is an article about manipulating XML data with XPath and XmlDocument:
     http://www.codeproject.com/KB/cpp/myXPath.aspx

    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Harry Zhu Wednesday, June 9, 2010 7:57 AM
    Thursday, June 3, 2010 1:27 AM