Solved Read attribute value from xml through batch script

August 23, 2012 at 03:21:45
Specs: Windows 7
Suppose,in my testfile.xml i have ,
<head ip="123" />
and if i have to fetch the value of ip i.e, 123 through batch scrpiting..
i have tried the code and i am not getting the value 123 in my output
this is the code i have written in test.bat
@echo on
for /F "usebackq tokens=*" %%I IN ('findstr /l "head ip=" C:\Temp\testfile.xml')
do call :readxml %%I
:readxml
set var1=%1
echo %var1%

I am new to Batch scripting please correct me if I am wrong in the code.

Thanks in Advance


See More: Read attribute value from xml through batch script

Report •

#1
August 23, 2012 at 05:20:01
Post a few lines.


====================================
Life is too important to be taken seriously.

M2


Report •

#2
August 23, 2012 at 05:40:26
@echo on
for /F "usebackq tokens=*" %%I IN ('findstr /l "head ip=" C:\Temp\testfile.xml')
do call :readxml %%I
:readxml
set var1=%1
echo %var1%

@Mechanix2Go
This is what i know..
Please let me know the solution


Report •

#3
August 23, 2012 at 19:28:14
✔ Best Answer
xml is always tedious/difficult/frustrating to process using batch, but here goeth the treacherous and futile assault thereon:

@echo off & setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('findstr /i "head ip=" test.xml') do (
set z=%%a
set z=!z:^<head ip=!
:get rid of the equals sign
set z!z!
set z=!z: /^>=!
call :readxml !z!
)
goto :eof
:readxml
echo in xml...
for %%a in (%1) do set test=%%~a
echo %test%
:end


Report •

Related Solutions

#4
August 23, 2012 at 21:18:54
Thanks alot nbrane !!

Report •

#5
August 24, 2012 at 03:17:33
Pls,post a few line of the XML.


====================================
Life is too important to be taken seriously.

M2


Report •

#6
August 27, 2012 at 03:18:38
@Mechanix2Go

<head ip="123"/>

This is my XML.


Report •

Ask Question