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.

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.