none
Hi tell me the error of code in c# windows application? RRS feed

  • Question

  • hi,

    I am creating xml file like this

     cn = new OleDbConnection(CONN_STRING);
    da = new OleDbDataAdapter("select satisfactoryitemcount as ConsumerRating  from inspection where InspectorperiodId=4147 Order by CreatedDateTime ASC", cn);
    DataSet    Inspection = new DataSet("InspectionSummaryReport");
                da.Fill(Inspection);
                 Inspection.WriteXml("C:\\aa.xml");

    it working fine and i am getting the output like this

    <?xml version="1.0" standalone="yes"?>
    <InspectionSummaryReport>
      <Table>
        <ConsumerRating>0</ConsumerRating>
      </Table>
    </InspectionSummaryReport>

    but i want out put like

    <?xml version="1.0" standalone="yes"?>
    <InspectionSummaryReport>
        <ConsumerRating>0</ConsumerRating>
    </InspectionSummaryReport>

    That is i dont want table tag.Any one help me urgent plz.

    Regards,
    venkat.

    Friday, March 21, 2008 7:29 AM

Answers

All replies

  • Hi venakt,

    As far as I know, there is a fixed format on XML file which was generated by DataSet class, you cannot change it by using DataSet.

    Code Snippet

    <?xml version="1.0" standalone="yes"?>

    <DataSet_Name>

      <table_name>

        <field1>2</ field1>

        < field2>12005</ field1>

      </ table_name >

      < table_name >

        <field1>3</ field1>

        < field2>12006</ field1>

      </ table_name > 

    </ DataSet_Name >

     

     

    And I think there are two approaches that you can take to figure the problem out.

    1.       Use the String.Replace method to remove the tags.

    2.       Generate the XML file by using XmlTextWriter, please check the URLs below.

    http://msdn2.microsoft.com/en-us/library/wkee9k2s(VS.71).aspx

    http://msdn2.microsoft.com/en-us/library/system.xml.xmltextwriter(VS.71).aspx

    Regards,

    Xun

     

    Monday, March 24, 2008 7:14 AM
  • Hi Venkat,

    I think first off, you should ensure the titles of your posts accurately match the question you are trying to ask, there is no errors occuring in the code that you have given.

    A quick google on the DataSet.WriteXml method would reveal that DataSet does in fact ALWAYS write the data structure to the resulting XML file.

    Xun Ye is correct in that you have two options, you can replace the offending XML via String.Replace, or you can define and create the XML file yourself using XMLTextWriter.

    Might I suggest it may be worthwhile (in terms of programmability support) creating and Object to contain the results from the data, which can then serialise itself to XML? This way you can save it to XML as required, but also extend it easily if required Smile
    Monday, March 24, 2008 2:14 PM