Write to XML with C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    Write to XML with C#

    I am trying to collect and write some temporary data to xml file
    before I put them into DB.

    I am writing into xml file like follows:
    private void WriteXML()
    {
    //Use the xmlTextWriter to open a new xml file
    XmlTextWriter writer = new
    XmlTextWriter(@ "C:\\Data\\tblP omocnaTablica.x ml",
    System.Text.Enc oding.UTF8);

    //Write the root element
    writer.WriteSta rtElement("tblT ableX");

    // Write the elements
    writer.WriteEle mentString("Cli entID", "2");
    writer.WriteEle mentString("Emp loyeeID", "4");
    writer.WriteEle mentString("Sho pID", "100");
    writer.WriteEle mentString("Pro ductID", "100");
    writer.WriteEle mentString("Qty ", "1");
    // end the root element
    writer.WriteEnd Element();
    // Flush
    writer.Flush();
    //Write the XML to file and close the writer
    writer.Close();
    }
    It is works and I get something like this:
    ClientID | EmployeeID | ProdavonicaID | ProductID | Qty |
    2 | 4 | 100 | 100 |1 |
    Two Questions
    1) How I can write a new rows without rewriting existing rows,
    for e.g.?
    2 | 4 | 124 | 25 |1 |
    etc.

    Result should be something like this:
    ClientID | EmployeeID | ProdavonicaID | ProductID | Qty |
    ------------------------------------------------------------------------
    2 | 4 | 100 | 100 |1 |
    2 | 4 | 124 | 25 |1 |

    2) How I can change one value in some row, for e.g.
    row 2 ShopID = 250, is that possible?
    Thanks in advance
    Mike
  • Andrew Faust

    #2
    Re: Write to XML with C#

    Why not just store the information in some temporary tables inside the
    database and move them to the final tables later?

    --
    Andrew Faust
    andrew[at]andrewfaust.com



    "Mike" <ablyplus@yahoo .comwrote in message
    news:g316i3d2g4 rhvrjaa37mbnj41 uos2604p6@4ax.c om...
    >I am trying to collect and write some temporary data to xml file
    before I put them into DB.
    >
    I am writing into xml file like follows:
    private void WriteXML()
    {
    //Use the xmlTextWriter to open a new xml file
    XmlTextWriter writer = new
    XmlTextWriter(@ "C:\\Data\\tblP omocnaTablica.x ml",
    System.Text.Enc oding.UTF8);
    >
    //Write the root element
    writer.WriteSta rtElement("tblT ableX");
    >
    // Write the elements
    writer.WriteEle mentString("Cli entID", "2");
    writer.WriteEle mentString("Emp loyeeID", "4");
    writer.WriteEle mentString("Sho pID", "100");
    writer.WriteEle mentString("Pro ductID", "100");
    writer.WriteEle mentString("Qty ", "1");
    // end the root element
    writer.WriteEnd Element();
    // Flush
    writer.Flush();
    //Write the XML to file and close the writer
    writer.Close();
    }
    It is works and I get something like this:
    ClientID | EmployeeID | ProdavonicaID | ProductID | Qty |
    2 | 4 | 100 | 100 |1 |
    Two Questions
    1) How I can write a new rows without rewriting existing rows,
    for e.g.?
    2 | 4 | 124 | 25 |1 |
    etc.
    >
    Result should be something like this:
    ClientID | EmployeeID | ProdavonicaID | ProductID | Qty |
    ------------------------------------------------------------------------
    2 | 4 | 100 | 100 |1 |
    2 | 4 | 124 | 25 |1 |
    >
    2) How I can change one value in some row, for e.g.
    row 2 ShopID = 250, is that possible?
    Thanks in advance
    Mike

    Comment

    • Mike

      #3
      Re: Write to XML with C#

      Is that a proper way to resolve that?

      On Sat, 27 Oct 2007 18:02:09 -0600, "Andrew Faust"
      <andrew@andrewf aust.comwrote:
      >Why not just store the information in some temporary tables inside the
      >database and move them to the final tables later?

      Comment

      • Andrew Faust

        #4
        Re: Write to XML with C#

        Why wouldn't it be? You have data to store and you have a database. Seems
        like a match made in heaven.

        Just so we're clear, I wasn't proposing you create a table on the fly, use
        it for a while and then destroy it. I was proposing you create a table (or
        tables) as part of your design that you always use for this temporary
        storage. You can delete the records after you've moved them to the final
        table and keep reusing the table.


        --
        Andrew Faust
        andrew[at]andrewfaust.com



        "Mike" <ablyplus@yahoo .comwrote in message
        news:jdmbi39hj2 9o32sfgmduh6e0j 2eaqkd1e4@4ax.c om...
        Is that a proper way to resolve that?
        >
        On Sat, 27 Oct 2007 18:02:09 -0600, "Andrew Faust"
        <andrew@andrewf aust.comwrote:
        >
        >>Why not just store the information in some temporary tables inside the
        >>database and move them to the final tables later?

        Comment

        Working...