Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Replace a string with another string in an XML file in VB.NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amritha.Datta@gmail.com - 17 Sep 2007 15:27 GMT
Hi,

I need to replace a string in an XML file. For that purpose I have
writtent he below code. It is working file for a small file say about
100 lines. But It failed and went to out of memory exception if I use
a bigger file.  Please let me know if there is any alternate way of
doing it. I do have a file with 3 million records.

Please help.

       Dim strFile As String = "C:\temp\TextXML"
       Dim result As String
       Dim reader As TextReader = File.OpenText(strFile)

       result = Regex.Replace(reader.ReadToEnd, "</
NewDataSet><NewDataSet>", "XYZ")
       reader.Close()

       FileOpen(1, strFile, OpenMode.Output, OpenAccess.Write,
OpenShare.LockWrite)

       'Writes the strDocument text to the file

       FileSystem.Write(1, result)

       'Closes the handle to the file, allowing all programs to edit
the file

       FileClose(1)

Thanks.
Jesse Houwing - 17 Sep 2007 16:04 GMT
Hello Amritha.Datta@gmail.com,

> Hi,
>
[quoted text clipped - 10 lines]
> Dim reader As TextReader = File.OpenText(strFile)
> result = Regex.Replace(reader.ReadToEnd, "</

NewDataSet>> <NewDataSet>", "XYZ")
NewDataSet>>
> reader.Close()
> FileOpen(1, strFile, OpenMode.Output, OpenAccess.Write,
[quoted text clipped - 10 lines]
>
> Thanks.

If you're replacing a fixed string, you're better off using String.Replace
instead of Regex.Replace. My guess is that that will solve your problem.

As your files get larger and larger, you might need to write a parser that
can read the contents from a buffer instead of reading the whole file all
at once, but this should suffice for the forseable  future.

--
Jesse Houwing
jesse.houwing at sogeti.nl

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.