0

This question is about finding a string in a string that is xml-like. Batch will have problems with characters like "<", but thats not the end, my text also has "&" echo %line% with an & in it throws me a "is not recognized as an external command" I am finding it hard to find an answer for this. I have a text file that contains an xml string like :

<ExampleTag1><error>Error message</error></ExampleTag1>

I wanted to use

set "line=<ExampleTag1><error>Error message</error></ExampleTag1>"
echo %line% | findstr /C:"ExampleTag1"

but its showing me error : "< was unexpected at this time"

I believe this is because %line% has "<" in it.

or actually is there a way to echo xml strings in batch?

Just echo %line% will show me the above error.

Can you guys help?

UPDATE : Actually I made a choice not to use batch to parse my text.

SomeDude
  • 13,876
  • 5
  • 21
  • 44
  • 2
    Possible duplicate of [Windows batch file - replace a string in an XML file](http://stackoverflow.com/questions/7976734/windows-batch-file-replace-a-string-in-an-xml-file) – Ken White Jan 14 '16 at 21:59

1 Answers1

1
@ECHO OFF
SETLOCAL
set "line=<ExampleTag1><error>Error message</error></ExampleTag"
echo "%line%" | findstr /C:"ExampleTag1"
ECHO %errorlevel%
GOTO :EOF

...assuming you want to set/examine errorlevel

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Thanks. Actually this was exactly I was doing i.e. check errorlevel but I missed quotes around %line%. Having said that, in my text file, I also have symbols like "&" that made the batch file approach a mess. I gave up, I am using perl now. – SomeDude Jan 15 '16 at 00:17