Set variables from a xml with spaces on a batch -



Set variables from a xml with spaces on a batch -

i have many xml files this:

<user_metadata> <user_id>141</user_id> <user_name>julios triton x (ssg)</user_name> <status>03</status> <user_level>4</user_level> <logins>41</logins> <time_online>207</time_online> <location>dungeon 17,21,11</location> <avatar>url</avatar> <class>1</class> </user_metadata>

and utilize batch file set variables xml data, have problems when string have space, code:

@echo off setlocal enabledelayedexpansion :data: %%a in (*.xml) ( set "id=" set "name=" set "location=" set "time=" /f "tokens=2 delims=>< " %%b in ( ' type "%%a" ^|findstr /i "<user_id>" ' ) set id=%%b /f "tokens=2 delims=>< " %%b in ( ' type "%%a" ^|findstr /i "<user_name>" ' ) set name=%%b /f "tokens=2 delims=>< " %%b in ( ' type "%%a" ^|findstr /i "<location>" ' ) set location=%%b /f "tokens=2 delims=>< " %%b in ( ' type "%%a" ^|findstr /i "<time_online>" ' ) set time=%%b ) echo %id% echo %name% echo %location% echo %time% pause

then result:

141 julios dungeon 207

on strings spaces "<user_name>julios triton x (ssg)</user_name>" first value before space (julios) want string (julios triton x (ssg)), same on string <location>dungeon 17,21,11</location>.

how can set total string variable?

any help appreciated, in advance!

class="lang-dos prettyprint-override">@echo off setlocal set "vars=user_id user_name location time_online" %%v in (%vars%) set "%%v=" /f "tokens=2,3delims=<>" %%a in (q24337603.txt) ( %%v in (%vars%) if "%%a"=="%%v" set "%%v=%%b" ) %%v in (%vars%) set %%v goto :eof

here's relatively easy way it. i've changed variable names convenience.

i used file named q24337603.txt containing info testing.

results:

user_id=141 user_name=julios triton x (ssg) location=dungeon 17,21,11 time_online=207

xml batch-file

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -