writing to XML file

Discussion in 'ASP .Net' started by slinky, Jun 11, 2007.

  1. slinky

    slinky Guest

    I'm struggling with what should be a very basic .aspx/XML issue. I
    have an XML file. I have a textbox for a user to enter data and a
    button to submit the data. I don't wont the user to see the other
    records on the screen. I'm using Visual Web Developer Express 2005,
    vb.NET) I've tried several different strategies from books and online
    examples, but I can't seem to get anywhere. I'm guessing I need to Dim
    a DataSet (even though I'm adding only one record). Of course I need
    to pass the value of my textbox into the XML file via an event handler
    on the button's code. Should I embed and INSERT query string into the
    button's click event? Please any advice would be appreciated. Thanks!
     
    slinky, Jun 11, 2007
    #1
    1. Advertising

  2. On Jun 11, 9:39 pm, slinky <> wrote:
    > I'm struggling with what should be a very basic .aspx/XML issue. I
    > have an XML file. I have a textbox for a user to enter data and a
    > button to submit the data. I don't wont the user to see the other
    > records on the screen. I'm using Visual Web Developer Express 2005,
    > vb.NET) I've tried several different strategies from books and online
    > examples, but I can't seem to get anywhere. I'm guessing I need to Dim
    > a DataSet (even though I'm adding only one record). Of course I need
    > to pass the value of my textbox into the XML file via an event handler
    > on the button's code. Should I embed and INSERT query string into the
    > button's click event? Please any advice would be appreciated. Thanks!


    http://groups.google.com/group/micr....aspnet/browse_thread/thread/5aa2d758049b3744
     
    Alexey Smirnov, Jun 11, 2007
    #2
    1. Advertising

  3. slinky

    slinky Guest

    No disrespect, but I went to that site and did not find anything
    pertinent to the needs of this very simple (for everyone but us
    newbies) request. Does anyone else know of some basic structure
    relative to the specific questions of my base post? Thanks!

    >On Jun 11, 3:59 pm, Alexey Smirnov <> wrote:
     
    slinky, Jun 11, 2007
    #3
  4. slinky

    sloan Guest

    There are kinda 2 ways you can go about this:

    Treat your xml as a XmlDocument

    that would involve you writing Xpath statements to find data.
    And would return XmlNodeList objects.

    OR

    Treat your backend data as a DataSet ( a strongly typed one would be
    better).
    However, to do this, the xml has to be in a specific format. (DataSet
    friendly).


    I would suggest this:

    Create your own strong dataset object.

    Right click / Add New Item (DataSet)
    Call it "MyFirstDataSet".

    Add a table in the designer. (if youre in 2.0 , DELETE the table adapter
    that gets auto created at the bottom)

    Add a table like "Employee"

    add columns like "SSN" , "LastName" , "FirstName".


    MyFirstDataSet ds = new MyFirstDataSet();
    ds.Employee.AddNewEmployeeRow ( "222222222" , "Smith" , "John" ) ;
    ds.Employee.AddNewEmployeeRow ( "333333333" , "Jones" , "Mary" ) ;

    ds.WriteXml (@"C:\myds.xml");

    ...............

    There is a ReadXml method as well.


    IF you do this, you'll see how the xml is formed, when you open the file in
    notepad.

    Then you can do stuff like

    MyFirstDataSet ds = new MyFirstDataSet();
    ds.ReadXml(@"C:\myds.xml");

    ds.Employee.Select ("SSN='222222222'");

    well, you gotta figure out what the above returns, and get a ref to it.

    The above should return 1 DataRow (I think?) and you'll be able to cast it
    as a
    MyFirstDataSet.EmployeeRow object.


    Something like that.


    If you go with a pure XmlDocument model, you'll have to learn some Xpath.


    If you want to go with a DataSet route, AND you don't have dataset friendly
    Xml to begin with, you can do this:
    http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!148.entry


    ...





    "slinky" <> wrote in message
    news:...
    > I'm struggling with what should be a very basic .aspx/XML issue. I
    > have an XML file. I have a textbox for a user to enter data and a
    > button to submit the data. I don't wont the user to see the other
    > records on the screen. I'm using Visual Web Developer Express 2005,
    > vb.NET) I've tried several different strategies from books and online
    > examples, but I can't seem to get anywhere. I'm guessing I need to Dim
    > a DataSet (even though I'm adding only one record). Of course I need
    > to pass the value of my textbox into the XML file via an event handler
    > on the button's code. Should I embed and INSERT query string into the
    > button's click event? Please any advice would be appreciated. Thanks!
    >
     
    sloan, Jun 11, 2007
    #4
  5. "slinky" <> wrote in message
    news:...
    > No disrespect, but I went to that site and did not find anything
    > pertinent to the needs of this very simple (for everyone but us
    > newbies) request. Does anyone else know of some basic structure
    > relative to the specific questions of my base post? Thanks!
    >


    Please scroll the page down, the code you've posted is more or less correct,
    you just need to modify a few things
     
    Alexey Smirnov, Jun 11, 2007
    #5
  6. slinky

    slinky Guest

    Thanks! I've kinda got some script below that I'm hoping to make work.
    I will have a textbox (txtEvent) that I've added to hold the value for
    which my submit button will write as a new "record" to the XML file.
    I'm guessing I need a SELECT INTO sql query in there somewhere for
    adding the record? Any help would be appreciated. Thanks!

    Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim myDataSet As New DataSet()
    myDataSet.ReadXml(Server.MapPath("timeline.xml"))
    txtNewEvent.DataBind()
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
    System.EventArgs)
    myDataSet.DataSet.WriteXml(Server.MapPath("timeline.xml"))
    End Sub

    > There is a ReadXml method as well.


    > IF you do this, you'll see how the xml is formed, when you open the file in
    > notepad.
    > Then you can do stuff like
    > MyFirstDataSet ds = new MyFirstDataSet();
    > ds.ReadXml(@"C:\myds.xml");
    > ds.Employee.Select ("SSN='222222222'");
    > well, you gotta figure out what the above returns, and get a ref to it.
    > The above should return 1 DataRow (I think?) and you'll be able to cast it
    > as a
    > MyFirstDataSet.EmployeeRow object.
    > Something like that.
     
    slinky, Jun 12, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelly G.

    Writing XML file

    Kelly G., Jan 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,843
    Kelly G.
    Jan 8, 2004
  2. HNguyen
    Replies:
    4
    Views:
    2,421
    HNguyen
    Dec 21, 2004
  3. Christopher Boomer
    Replies:
    0
    Views:
    412
    Christopher Boomer
    Jul 28, 2003
  4. jkflens
    Replies:
    2
    Views:
    1,514
    jkflens
    May 30, 2006
  5. Erik Wasser
    Replies:
    5
    Views:
    481
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page