drtopserv
asked on
open text/xml file in memory and delete entire line if specific string found in it then save
Hi,
I`m seeking for away (fast) to read text/xml in memory then delete entire line if specific string found in it (string: "ID>" .
and to replace a word "root>" found in a line to "usual>" instead , then close save file and close.
i`d like to use access to perform this task using vba.
I`m seeking for away (fast) to read text/xml in memory then delete entire line if specific string found in it (string: "ID>" .
and to replace a word "root>" found in a line to "usual>" instead , then close save file and close.
i`d like to use access to perform this task using vba.
ASKER
I have google and found many codes around.
http://ezinearticles.com/?How-To-Use-VBA-Code-To-Remove-Blank-Lines-From-A-Text-File&id=7393752
i still can`t figure out how to manipulate the code to delete the entire line of specific string found in it .
http://ezinearticles.com/?How-To-Use-VBA-Code-To-Remove-Blank-Lines-From-A-Text-File&id=7393752
i still can`t figure out how to manipulate the code to delete the entire line of specific string found in it .
in short, the relevant code goes like this
well, instead of that "select case" statements, you do:
and that variable will just make to skip the line.
tip: instead of using the plain & to concatenate strings like in that article, you really should go the stringbuilder class:
http://www.vbusers.com/code/codeget.asp?ThreadID=601&PostID=1
performance increase, especially for larger files is dramatic
Select Case Len(txt)
Case 0
includeLine = false
well, instead of that "select case" statements, you do:
if txt like "*ID>*" then includeLine = false
and that variable will just make to skip the line.
tip: instead of using the plain & to concatenate strings like in that article, you really should go the stringbuilder class:
http://www.vbusers.com/code/codeget.asp?ThreadID=601&PostID=1
performance increase, especially for larger files is dramatic
ASKER
Wow, the article you mention is so complicated for me!
I`m not that strong enough to understand how to modify this code for my needs.
I still missing how to replace string ="dataroot" to "usaul" in the xml/text file
I`m not that strong enough to understand how to modify this code for my needs.
I still missing how to replace string ="dataroot" to "usaul" in the xml/text file
don't bother about that stringbuilder link for the moment, take it for later.
for your "replace", you would do:
for your "replace", you would do:
if txt like "*dataroot>*" then txt = replace(txt, "dataroot>", "usual>")
ASKER
Also, is it this only way i can delete the line in text file , means to write new file skiping the lines which i don`t need ?
also i don`t need to write another file, just to overwrite the existing one
also i don`t need to write another file, just to overwrite the existing one
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you said "note that I would NOT do that way in really production applications ?"
how you would do it?
how you would do it?
as I write: write as new file, and then copy/move if completed.
ASKER
I have string =generated=2013-09-02T11:4 3:05">
I need to delete it , or replace it with nothing.. how can i do it , when that date and time change dynamically?
I need to delete it , or replace it with nothing.. how can i do it , when that date and time change dynamically?
you can add this line:
if txt like "*generated=[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]"">*" then
Dim i as integer
i = instr(1, txt, "generated=")
txt = left(txt, i -1) & mid(txt, i + 29)
end if
ASKER
thnx alot angelIII, plz I think you are the only one who could help me so far with this problem with my xml .
are you good in exporting tables in access to XML?
are you good in exporting tables in access to XML?
I have not actually done that, as I use MS Access close to never in my day to day job.
but it looks like it should be easy:
http://office.microsoft.com/en-us/access-help/exporting-to-xml-from-access-HA001034561.aspx
but it looks like it should be easy:
http://office.microsoft.com/en-us/access-help/exporting-to-xml-from-access-HA001034561.aspx
ASKER
Yea, but link u mentioned could do only export of a table as a flat, without relating tables.
all element one after the other (no sub-child/sub elements)
all element one after the other (no sub-child/sub elements)
I think the best tip then I can give you is to place a dedicated question for that.
put ms access , VBA and XML as your zones.
put ms access , VBA and XML as your zones.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
of course, the XML file can be considered a "text" file having indeed line breaks, so you might work that way indeed.
you can read the file into memory indeed, do the replacements, and save back.
which part is what you don't know how to do, actually?