Results 1 to 2 of 2

Thread: Reading data from an XML document

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    14

    Reading data from an XML document

    I have an XML document created and I want to write code to read the document and store all the data (inlcuding everything... all tags, attributes, everything!) into a string. I need to be able to pass this string to a function.

    Basically, I would like to see the SAME content within the xml file in a text file ..... (I just need to be able to do this)



    How do I go about this?
    Any sample code would be greatly appreciated!!!


    Thx in advance!


    BTW .... I am using a webform in .NET!
    Last edited by Islesfan; Jul 27th, 2004 at 01:57 PM.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. 'C#
    2. String myFile = @"C:\test.xml";
    3. System.IO.FileStream fs =
    4. new System.IO.FileStream(myFile, System.IO.FileMode.Open , System.IO.FileAccess.Read);
    5. Byte[] myxml = new Byte[fs.Length];
    6.  
    7. fs.Read(myxml, 0, myxml.Length);
    8. System.Text.ASCIIEncoding asci = new System.Text.ASCIIEncoding();
    9.  
    10. String s = asci.GetString(myxml);
    11.  
    12. 'i'm displaying to screen,
    13. 'you can google how to write a string to a file
    14. Console.WriteLine(s);
    15.  
    16. Console.Read();
    17.  
    18. 'vb
    19. Dim fs As New System.IO.FileStream("C:\test.xml",System.Io.FileMode.Open, System.Io.FileAccess.Read)
    20.  
    21. Dim myxml(fs.length) As Byte
    22. fs.Read(myxml, 0, myxml.Length)
    23. Dim asci As New  System.Text.ASCIIEncoding
    24. Dim s as String  = asci.GetString(myxml)
    25. 'i'm displaying to screen,
    26. 'you can google how to write a string to a file
    27. Console.WriteLine(s)
    28. Console.Read()
    Last edited by nemaroller; Jul 27th, 2004 at 03:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width