Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

xml - 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 "{var1:=text()}" --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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, you're not using Xidel correctly.
First of all, the only way to make Xidel variables available in cmd is through the use of a FOR-loop.
Secondly, in this situation you shouldn't enclose your query with curly brackets. Those are meant for creating JSONs, amongst other things.
And thirdly, officially it's --output-format=cmd, but I guess Benito - Xidel's author - has been forgiving for people who forget the =, as --output-format cmd seems to work as well. Should you use the =, don't forget to escape it with a ^, because it's a special character.

So your FOR-loop would then look like this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...