Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi!
I have an XML-file where the string <?xml version="1.0"?> occurs several times. I would like to delete all lines equal to this string and keep the rest (saving the result in output.txt). The string at the top including the encoding, I want to keep. (Actually, I have 450 XML-files where I want to delete all lines equal to <?xml version="1.0"?>.)
The <, ?, space, = and " within the string cause me trouble. I just strip it down to 0"? to avoid including the first line in the XML-file. However, I can't figure out how to tell the system to search for the string "0"?".
My starting point (saved in test.bat)
setLocal enableDELAYEDexpansion
set mystring="0"?"
find /v /i %mystring% < 104_arstat.xml > output.txtExample (104_arstat.xml)
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="I:\arkart\arstat\kode\arstat_komm.xslt"?>
<ROTNODE>
<TOTALT>
<?xml version="1.0"?>
<ROWSET>
<ROW>
<KOMM>101</KOMM>
<LAND_DAA>596410</LAND_DAA>
<VANN_DAA>45940</VANN_DAA>
<TOTAL_DAA>642350</TOTAL_DAA>
</ROW>
</ROWSET>
</TOTALT>
<AREALTILSTAND>
<?xml version="1.0"?>
<ROWSET>
...
</AREALTILSTAND>
<SKOG>
<?xml version="1.0"?>
<ROWSET>
<ROW>
<MSTATSKOG>0</MSTATSKOG>
<SKOG_BESKRIVELSE>Ikke skog</SKOG_BESKRIVELSE>
<SAREAL> 181569.2</SAREAL>
...I would appreciate any help.
Thanks.Best regards
Anne, Norway

Thanks for your reply and suggestion.
It works a little "too good", meaning also the two first lines in the file are gone. And I need to keep those two lines (for displaying the xml-file with an xslt-file in a web browser).output.txt looks like this:
<ROTNODE>
<TOTALT>
<ROWSET>
<ROW>
<KOMM>104</KOMM>
<LAND_DAA>58020</LAND_DAA>
<VANN_DAA>5470</VANN_DAA>
<TOTAL_DAA>63490</TOTAL_DAA>
</ROW>
</ROWSET>
</TOTALT>
<AREALTILSTAND>
<ROWSET>
<ROW>
<MSTATTYPE>1</MSTATTYPE>
<TYPE_BESKRIVELSE>Fulldyrka jord</TYPE_BESKRIVELSE>
<AAREAL> 6424.6</AAREAL>
...

Yes, finally I want a bat-file going through all my xml-files in a folder and replacing the existing xml-files with new xml-files without the <?xml version="1.0"?> lines. For now, I'm just testing how to make it work on one single xml-file.

OK try this:
@echo off
cls
setlocal enabledelayedexpansionfindstr/c:"<?xml version=\"1.0\"?>" /i /v input.xml > output.txt

Hahaha, yes, I just found it out myself:
findstr /v /i /c:"<?xml version=\"1.0\"?>" 101_arstat.xml > output.txt
As Wahine, I just figuered out that /c: does the trick.
(I read the findstr /? one more time - a little bit more carefully this time.)Thanks for the tips reagrding the use of findstr in stead of find and the use of \ in front of the " within the string.

Thank you for coming back to report your success. Almost 1 a.m. here so am going to bed now. Will check in later this morning.
Good luck with the rest of your project and don't hesitate to come back for support if you need it.
Wahine..

You're welcome.
Yes, I managed to succesfully search through all my *.xml, createing new *_ff.xml without the <?xml version="1.0"?> lines, deleting the orignal *.xml and then renaming the new *_ff.xml-files back to *.xml. (I want to keep the original filenames.)
Example:
1) 106_arstat.xml (WITH the <?xml version="1.0"?>-lines) is ...
2) ... changed to106_arstat_ff.xml (WITHOUT the <?xml version="1.0"?>-lines)
3) 106_arstat.xml in step 1) is deleted
4) 106_arstat_ff.xml is renamed to 106_arstat.xmlfor %%f in (*stat.xml) do (
findstr /v /i /c:"<?xml version=\"1.0\"?>" %%f > %%~nf_ff.xml
del %%f
)
for %%f in (*.xml) do rename "%%f" *stat.xmlhttp://www.computerhope.com/forhlp.htm was a nice starting point for the "for-do"-matter.

Anne, thank you for coming back to advise about the successful completion of your project. It's been a pleasure collaborating with you.
Good luck
Wahine.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |