Solved Fetch the content of xml tag using batch script

August 27, 2012 at 22:52:27
Specs: Windows 7
<Main display="NORMAL">
<Port name="read_abc" exe="NO">
<input>
<struct file="C:\temp" sign="id1"/>
</input>
<output>
<return code="33" shortmsg="Implementation not found for commande]."/>
</output>
</Port>
<Port name="write_abc" exe="NO">
<input>
<struct file="C:\temp" id="id1"/>
</input>
<output>
<return code="1" shortmsg="NOTEXECUTED" longmsg="Not execute due to previous error"/>
</output>
</Port>
</Main>


I want the value of <return code> inside <Port name="write_abc" exe="NO">
, inside <output> tag... ie, the value 1. using batch script


See More: Fetch the content of xml tag using batch script

Report •


✔ Best Answer
August 28, 2012 at 23:21:02
this sounds pretty close:
http://www.computing.net/answers/pr...
(post #13)
you two must be working on the same project, or taking the same class, Lol!


#1
August 28, 2012 at 01:33:24
:: ===== script starts here ===============
::
:: subria.bat 2012-08-28 15:16:05.92
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=2 delims= " %%a in (my.xml) do (
set S=%%a
)
set S=!S:~6!
set S=!S:~0,-1!
echo.!S!
goto :eof
::====== script ends here =================


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

M2


Report •

#2
August 28, 2012 at 02:29:07
Thanks mechanix2go...
this is good...
but i want the program to search the tag where name=write_abc and then to output tag
finally fetch the value of the return code.

if the <port name=read_abc>, there should not be any search


Report •

#3
August 28, 2012 at 03:30:44
Not clear.

It does not contain:

name=write_abc


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

M2


Report •

Related Solutions

#4
August 28, 2012 at 06:00:51
pls refer the line 10...
the xml contains number of port tags with read_abc, and write_abc

the batch file should check the tag port only if the name attribute is write_* not read_*
and then check the return code of output tag, then take the action based on the return code.


Report •

#5
August 28, 2012 at 23:21:02
✔ Best Answer
this sounds pretty close:
http://www.computing.net/answers/pr...
(post #13)
you two must be working on the same project, or taking the same class, Lol!

Report •

#6
August 29, 2012 at 22:21:44
thanks nbrane,
how should i hav to compare the string containing number of spaces
eg:
          <operation />

here the comparison has to be with operation tag along with spaces before...
help me with this please.


Report •

#7
August 29, 2012 at 22:58:06
see flycode post: i think that might work: add space into the delimiters: "delims= _" But you need to account for that. I shifted the vars to get it to work for flycode. With these kinds of file formats, with batch, you usually just have to keep experimenting, or at least I do, Lol! Batch will strip off leading spaces when you use space in delimiters. No data, no variable. So %%a is always the first actual-data-item on a line, no matter how many spaces precede it. BUT if spaces inside data, watch out! you need to account for that also by shifting the vars. This is only reliable if you have very fixed data format, otherwise, use another approach:(vbscript, perl, etc)

Report •


Ask Question