Lost exclam points in search and replace

Hewlett-packard / Hp compaq 8000 elite cmt...
October 6, 2010 at 14:26:10
Specs: Windows XP, 3.324 GHz / 3579 MB
I thought I had found a solution here:
http://www.computing.net/answers/pr...

Once I tried to toggle delayedexpansion, I can't even get the code to run at all....command window jsut flashes and closes.

Thanks in advance for any help you can provide....
::
::
FOR /f "tokens=* delims=" %%t in (C:\CDE_update\sco_content.xml) do (
set str=%%t
set dojump=no
::
setLocal EnableDelayedExpansion
::
if not !str:isNumbered=!==!str! (
echo.
echo this is a bulletitem
pause
rem
rem check for bulletitems
rem
if not !str:BulletItemLevel2Element=!==!str! set str=" <sb:BulletItemLevel2Element>"
if not !str:BulletItemLevel3Element=!==!str! set str=" <sb:BulletItemLevel3Element>"
if not !str:BulletItemLevel4Element=!==!str! set str=" <sb:BulletItemLevel4Element>"
if not !str:BulletItemLevel5Element=!==!str! set str=" <sb:BulletItemLevel5Element>"
if not !str:BulletItemLevel6Element=!==!str! set str=" <sb:BulletItemLevel6Element>"
set str=!str:~1,-1!
echo !str! >> C:\CDE_update\sco_content_new.xml
set dojump=yes
)
::
if [!dojump!]==[no] (
echo.
echo this is not a bulletitem
pause
rem
rem write string to new sco_content file
echo !str! >> C:\CDE_update\sco_content_new.xml
)
::
endlocal
)
::
::
:end


See More: Lost exclam points in search and replace

Report •

#1
October 6, 2010 at 17:59:55
why are you using batch to parse xml ?? batch (cmd.exe) is not suitable even for normal file processing. If possible, use a programming language with XML parsing libraries..

Show a sample of your XML and what you want to parse.

GNU win32 packages | Gawk


Report •

#2
October 6, 2010 at 19:19:49
Thanks for the note.

I'm obviously not a programmer. If I knew a better method, I would use it. The files transformed wrong, and the only other option we have is to manually edit them. If I can come up with a method to automate it, we save days worth of work.

I have several hundred zip files that I have to unzip the sco_content.xml file out of, then correct. I have to find the statements that contain [ isNumbered="false" ] and remove it, but only for Bulletitem2 and greater......not Bulletitem1's.

Then I have to add the corrected file back into the .zip file.

So lines 4 and 7 from the following snippet of code need to change.....

</sb:ParagraphElement>
<sb:BulletItemLevel1Element isNumbered="false">
<text>Demonstrate active listening skills.</text>
<sb:BulletItemLevel2Element isNumbered="false">
<text>Identify active listening skills.</text>
</sb:BulletItemLevel2Element>
<sb:BulletItemLevel2Element isNumbered="false">
<text>Practice active listening skills.</text>
</sb:BulletItemLevel2Element>
</sb:BulletItemLevel1Element>
</sb:BodyTextElement>
</sb:ScreenElement>
</sb:TopicElement>
<sb:TopicElement>

Since I'm not touching all Bulletitem statements...first I check to see if the statement contains "isnumbered". Then I check to see if the BulletitemLevel2 or greater. If it is, I change

<sb:BulletItemLevel2Element isNumbered="false">
to
<sb:BulletItemLevel2Element>

leaving the leading spaces in for readability.

I've been able to do everything I need to do, it's just that all the !'s in the file vanish.

I re-wrote the code to attempt to toggle delayedExpansion, which is apparently the only way to get the string into a variable with the ! characters intact. Prior to that, I had it enabled throughout the entire batch file, in order to use variables for the filenames, subfolders, destination folders, etc.


Report •

#3
October 6, 2010 at 19:41:07
ok considering your requirement is trivial, i will take it that you really don't need an actual parser.

download gawk for windows then do this

C:\test>more file

</sb:ParagraphElement>
<sb:BulletItemLevel1Element isNumbered="false">
<text>Demonstrate active listening skills.</text>
<sb:BulletItemLevel2Element isNumbered="false">
<text>Identify active listening skills.</text>
</sb:BulletItemLevel2Element>
<sb:BulletItemLevel2Element isNumbered="false">
<text>Practice active listening skills.</text>
</sb:BulletItemLevel2Element>
</sb:BulletItemLevel1Element>
</sb:BodyTextElement>
</sb:ScreenElement>
</sb:TopicElement>
<sb:TopicElement>

C:\test>gawk "/BulletItemLevel2Element/  && /isNumbered=\"false\"/{next}1" file
</sb:ParagraphElement>
<sb:BulletItemLevel1Element isNumbered="false">
<text>Demonstrate active listening skills.</text>
<text>Identify active listening skills.</text>
</sb:BulletItemLevel2Element>
<text>Practice active listening skills.</text>
</sb:BulletItemLevel2Element>
</sb:BulletItemLevel1Element>
</sb:BodyTextElement>
</sb:ScreenElement>
</sb:TopicElement>
<sb:TopicElement>

To use it in your batch

@echo off
.....
for ... ( *zip)  do (
   unzip command to unzip your xml here   
   gawk "/BulletItemLevel2Element/  && /isNumbered=\"false\"/{next}1" xml_unzipped.xml > temp
   ren temp xml_unzipped.xml
....
....
)

GNU win32 packages | Gawk


Report •

Related Solutions

#4
October 7, 2010 at 16:29:55
Thanks for the reply......

I'll try to incorporate gawk tomorrow...and will let you know the result


Report •

Ask Question