代码拉取完成,页面将自动刷新
@if (@X)==(@Y) @end /* JScript comment
@echo off
set "file=%~f1"
set "xpath=%~2"
set "option=%~3"
set "node=%~4"
if "%~2" equ "" (
goto :printHelp
)
for %%# in ("-h" "-help" "/h" "/help" "") do (
if /i "%~1" equ %%# (
goto :printHelp
)
)
if exist "%file%\" (
echo file "%~1" does not exist
exit /b 3
)
if not exist "%file%" (
echo file "%~1" does not exist
exit /b 4
)
cscript //E:JScript //nologo "%~f0" /file:"%file%" /xpath:"%xpath%" /option:"%option%" /node:%node%
exit /b %errorlevel%
:printHelp
echo %~nx0 prints the value (or list of values)
echo of xml attribute/node in xml by given xpath expression
echo(
echo Usage:
echo(
echo call %~nx0 "filePath" "xpathExpression"
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
if (WScript.Arguments.length<2)
{
WScript.Echo("Not enough arguments");
WScript.Quit(3);
}
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
var xp=WScript.Arguments.Named.Item("xpath");
xp=replaceAll(xp,"'",'"');
var option=WScript.Arguments.Named.Item("option");
var node_n=parseInt(WScript.Arguments.Named.Item("node"));
var objDoc;
var objNodes;
var loaded;
try {
objDoc = WScript.CreateObject("MSXML.DOMDocument");
loaded=objDoc.load(WScript.Arguments.Named.Item("file"));
} catch (err){
WScript.Echo("Error while parsing the xml");
WScript.Echo(err.message);
WScript.Quit(1);
}
if(!loaded){
WScript.Echo("Error while parsing the xml");
WScript.Echo("");
WScript.Echo("Error Code:"+objDoc.parseError.errorCode);
WScript.Echo("");
WScript.Echo("Line:"+objDoc.parseError.line+" Posotion:"+objDoc.parseError.filepos);
WScript.Echo("");
WScript.Echo("Reason:"+objDoc.parseError.reason);
WScript.Echo("");
WScript.Echo("URL:"+objDoc.parseError.url);
WScript.Echo("");
WScript.Echo(objDoc.parseError.srcText);
WScript.Quit(5);
}
try {
var objNodes = objDoc.selectNodes(xp);
} catch (err){
WScript.Echo("invalid xpath expression");
WScript.Echo(err.message);
WScript.Quit(2);
}
if(!isNaN(node_n)) {
if(node_n>=objNodes.length){
WScript.Echo("Out of nodes range");
WScript.Echo("Nodes length is: "+objNodes.length);
WScript.Quit(35);
}
if(option.toLowerCase()=="xml"){
WScript.Echo(objNodes.item(node_n).xml);
} else {
WScript.Echo(objNodes.item(node_n).text);
}
} else {
for (var i=0;i<objNodes.length;i++){
if(option.toLowerCase()=="xml"){
WScript.Echo(objNodes.item(i).xml);
} else {
WScript.Echo(objNodes.item(i).text);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。