Try this:
Main Topics
Browse All TopicsI've got a settings.xml file that contains the lines below:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationSettings xmlns:xsi="http://www.w3.o
<MessageCaption>EmunWorks<
<_userName>admin</_userNam
<_fullName>Emun Admin</_fullName>
<_shortName />
<_emailAddress />
<_typeOfConnection>WS</_ty
<_LANLocation>NF-LAPTOP\em
</ApplicationSettings>
I am trying to create a batch file to read the value in the <_LANLocation> spot but cannot get it to work. Below is what I have in my batch file:
@echo off
for /f "tokens=2 delims=><" %%a in ('type settings.xml ^| find "<_LANLocation>"') do set ip=%%a
echo The IP address is %ip%
Can you help me with what I'm doing wrong here?
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thank you nafaught.
OK, this is how I think of the FOR command. Sorry if you already know some of the basics.
Whatever is in the ( ) part of the command is looked at or executed first. I suppose it's easiest to regard this as the "source" data. The ( ) can contain:
A file name, eg. "settings.xml",
A literal text string if double-quoted,
A command if single-quoted, the results of the command then being your source,
A number of other types of source not applicable to your example or needs.
So, in your case the bit in the ( ) is just a command to find only one line in the source file. The FOR command will walk through as many lines as there are in the source data processing each in turn, so it's a loop. Your's has only one line, but just remember that the FOR command is a looping thing.
In my troubleshooting example I added a block of echo commands by placing an opening ( after the DO part of the command, and then used a closing ) after the last echo command. That is still part of the loop. The FOR command will only exit that loop after the last line of the source data is parsed.
So, for each line in the source data, the process will look for your specified delimeters. Consider these like field separators. When it gets to the first delimeter, it grabs the chunk of data up to that as Token1. The chunk grabbed up to the next delimeter found is Token2, etc.
My example used "tokens=1-4", so it's going to break the line into 4 chunks separated by each instance of a < or > and that includes the leading white space before the first <
Because you used a starting variable of %%a then that chunk of white space is Token1 and will be stored in variable %%a. The 2nd Token will be the part after the first < delimeter and the next delimeter which is > and this will be stored in %%b, etc, etc.
Not sure if this is going to line up:
<_LANLocation>NF-LAPTOP\emun
| 1 | 2 | 3 | 4 |
%%a %%b %%c %%d
If your filtered line contained more than just 4 delimeted chunks, then by specifying "tokens=1-4" you would be telling it not to grab any more chunks of data after Token4 or %%d
There are different ways to do this, so Shift3's suggestion is actually correct also, as demonstrated below.
If instead you just used "tokens=3 delims=><" then you are just telling it to START at the 3rd token defined by your delimeters. In that case because your starting variable is %%a then THAT would be storing the 3rd token or 3rd chunk of data.
Use the modified troubleshooting batch file below to demonstrate this:
Remember these rules:
Whatever you specify as delimeters will NOT be included in the data stored in the variables. You are grabbing the data BETWEEN the delimeters.
You can use an uppercase or lowercase letter as your starting variable as long as you match the case of the variables on the other side of the (source) part of the command. So if you start with %%A then %%a is not the same.
The starting variable does not have to be %%a
It can be any letter of the alphabet, but remember to leave enough spare to hold as many tokens as you are specifying. Some people use a different starting letter depending on the type of data they are parsing, but it's a whole lot easier "counting" up from %%a than from something like %%i
Regards
Bill
Business Accounts
Answer for Membership
by: Shift-3Posted on 2009-11-06 at 08:02:04ID: 25760274
Try changing tokens=2 to tokens=3.
If that doesn't work, what output do you get?
Is the XML file all on one line, or are there line breaks?