user3338693
user3338693

Reputation: 1

Has anyone successfully exported xidel output vars to cmd?

I'm using xidel to extract a value from a specific tag in a XML file, and export it as a var to cmd. However, the vars don't seem to be exported at all.

example I'm using:

xidel "in.xml" -e "<tagofinterest>{var1:=text()}</tagofinterest>" --output-format cmd

I get the output:

**** Retrieving:in.xml ****  
**** Processing: in.xml ****  
** Current variable state: **  
SET var1=1234  

(where 1234 is contained in in.xml) but var1 is not set as a variable available from the command prompt window. This is on a Windows 7 machine. Any insight would be much appreciated - I don't know if I'm using xidel incorrectly or there's a bug with cmd var output.

Upvotes: 0

Views: 958

Answers (3)

Reino
Reino

Reputation: 3443

No, you're not using xidel correctly.

  1. The only way to export internal variables is through the use of a FOR-loop.
  2. Officially it's --output-format=cmd, but I guess Xidel's author has been forgiving for people who forget the =, as --output-format cmd seems to work as well. Should you use the =, then don't forget to escape it with a ^, because it's a special character.

So in your FOR-loop would then look like this:

FOR /F "delims=" %A IN ('
  xidel.exe -s "in.xml" -e "<tagofinterest>{var1:=.}</tagofinterest>" --output-format^=cmd
') DO %A

In a -file don't forget to escape the percent sign by adding another one:

FOR /F "delims=" %%A IN ('
  xidel.exe -s "in.xml" -e "<tagofinterest>{var1:=.}</tagofinterest>" --output-format^=cmd
') DO %%A

Alternatively you could use XPath instead of pattern matching:

FOR /F "delims=" %A IN ('
  xidel.exe -s "in.xml" -e "var1:=//tagofinterest" --output-format^=cmd
') DO %A

Upvotes: 1

lemale
lemale

Reputation: 1

For one or more variables:

for /f "delims=" %%a in ('xidel "in.xml" -s --output-format=cmd -e "{var1:=...}" -e "{var2:=...}" -e "{var3:=...}"') do %%a

echo %var1%
echo %var2%
echo %var3%

pause

Upvotes: 0

foxidrive
foxidrive

Reputation: 41257

See how this works

@echo off
for /f "delims=" %%a in ('xidel "in.xml" -e "{var1:=text()}" --output-format cmd ^|find /i "set " ') do %%a
set var1
pause

Upvotes: 0

Related Questions