XMLStarlet不打印全系列 [英] XMLStarlet does not print full line

查看:353
本文介绍了XMLStarlet不打印全系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的批处理的一个问题。 XMLStarlet不显示我的完整产品线。

I have a problem with my batch. XMLStarlet does not show me the complete line.

不过,我得到下面仅批处​​理文件 3DS 和行的其余部分不会显示。

However, I get with the batch file below only 3DS and the rest of the line is not shown.

输出应该只从第一个标题版本信息包含的 3DS 在XML文件中的标记线,例如 9.4.0-21 3DS

Output should be only the version information from first title tag line containing 3DS in XML file, e.g. 9.4.0-21 without 3DS.

我将任何答案非常高兴。

I would be very glad about any answer.

我的批处理文件:

@echo off
cls
echo.
echo.
echo ----------- Nintendo 3DS Firmware Checker --------------------------------------
echo --------------------- A CMD based Tool -----------------------------------------
echo.
echo.
echo.
httpget http://yls8.mtheall.com/ninupdates/feed.php nintendo3dsupdate.xml
for /f %%i in ('XML.EXE sel -t -v "//channel/item/title" "nintendo3dsupdate.xml"') do set "var111=%%i" >nul
echo.
echo.
echo                "%var111%" is the currently 3ds firmware.
echo.
echo.
pause
exit

在XML文件的内容的 nintendo3dsupdate.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
    <channel>
      <title>Sysupdate Reports</title>
      <atom:link href="http://yls8.mtheall.com/ninupdates/feed.php" rel="self" type="application/rss+xml" />
      <link>http://yls8.mtheall.com/ninupdates/reports.php</link>
      <description>Nintendo System Update Reports</description>
      <lastBuildDate>Thu, 11 Dec 2014 23:05:04 +0000</lastBuildDate>
      <language>en</language>
      <sy:updatePeriod>hourly</sy:updatePeriod>
      <sy:updateFrequency>1</sy:updateFrequency>
        <item>
        <title>3DS 9.4.0-21</title>
        <link><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-11-14_07-05-04&sys=ctr]]></link>
        <guid isPermaLink="true"><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-11-14_07-05-04&sys=ctr]]></guid>
        <description>3DS 9.4.0-21</description>
        <pubDate>Thu, 11 Dec 2014 23:05:04 +0000</pubDate>
    </item>
    <item>
        <title>3DS 9.3.0-21 (stage5)</title>
        <link><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-08-14_07-45-04&sys=ctr]]></link>
        <guid isPermaLink="true"><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-08-14_07-45-04&sys=ctr]]></guid>
        <description>3DS 9.3.0-21 (stage5)</description>
        <pubDate>Mon, 08 Dec 2014 23:45:03 +0000</pubDate>
    </item>
    <item>
        <title>3DS 9.3.0-21 (stage4)</title>
        <link><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-08-14_07-35-04&sys=ctr]]></link>
        <guid isPermaLink="true"><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-08-14_07-35-04&sys=ctr]]></guid>
        <description>3DS 9.3.0-21 (stage4)</description>
        <pubDate>Mon, 08 Dec 2014 23:35:03 +0000</pubDate>
    </item>
    <item>
        <title>3DS 9.3.0-21 (stage3)</title>
        <link><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-08-14_07-25-04&sys=ctr]]></link>
        <guid isPermaLink="true"><![CDATA[http://yls8.mtheall.com/ninupdates/reports.php?date=12-08-14_07-25-04&sys=ctr]]></guid>
        <description>3DS 9.3.0-21 (stage3)</description>
        <pubDate>Mon, 08 Dec 2014 23:25:04 +0000</pubDate>
    </item>
 </channel>
</rss>

缩进与水平制表符。有2个选项卡留给&LT;标题&GT; 3DS 9.4.0-21&LT; /标题方式&gt;

推荐答案

下面是批处理code,从第一个标题获取版本信息代码开头的 3DS 从XML文件:

Here is the batch code to get version information from first title tag starting with 3DS from XML file:

@echo off
cls
echo.
echo.
echo ----------- Nintendo 3DS Firmware Checker --------------------------------------
echo --------------------- A CMD based Tool -----------------------------------------
echo.
echo.
echo.
del "%TEMP%\nintendo3dsupdate.xml">nul 2>nul
set FirmwareVersion3DS=
httpget http://yls8.mtheall.com/ninupdates/feed.php "%TEMP%\nintendo3dsupdate.xml"
for /F "usebackq tokens=3 delims=< " %%V in (`%SystemRoot%\System32\findstr.exe "<title>3DS" "%TEMP%\nintendo3dsupdate.xml" 2^>nul`) do (
    set "FirmwareVersion3DS=%%V"
    goto OutputInfo
)
echo Failed to determine version of 3DS firmware!
echo.
goto :EndBatch

:OutputInfo
echo.
echo.
echo                "%FirmwareVersion3DS%" is the current 3DS firmware.
echo.
echo.
set FirmwareVersion3DS=

:EndBatch
del "%TEMP%\nintendo3dsupdate.xml">nul 2>nul
pause

XML文件由命令首先分析 FINDSTR 寻找简单文本字符串&LT;标题&GT; 3DS 返回

The XML file is parsed first by command findstr searching for simple text string <title>3DS returning

        <title>3DS 9.4.0-21</title>
        <title>3DS 9.3.0-21 (stage5)</title>
        <title>3DS 9.3.0-21 (stage4)</title>
        <title>3DS 9.3.0-21 (stage3)</title>

这4条线各缩进2个选项卡直接重定向到指挥这样会将使用左尖括号和空格字符作为分隔符,每行。因此,第一线被分成:

Those 4 lines each indented with 2 tabs are redirected directly to command for which splits each line using left angle bracket and space character as delimiter. Therefore first line is split to:


  • 标记1: (两个水平选项卡)

  • 标记2:标题&GT; 3DS

  • 令牌3: 9.4.0-21

  • 标记4: /标题&GT;

  • token 1:                  (two horizontal tabs)
  • token 2: title>3DS
  • token 3: 9.4.0-21
  • token 4: /title>

由于只是版本号很感兴趣,只是令牌的 3 是分配给循环变量 V 分配旁边的环境变量的 FirmwareVersion3DS

As just the version number is of interest, just token 3 is assigned to loop variable V assigned next to environment variable FirmwareVersion3DS.

有关此任务只是第一行与版本信息的兴趣。所以循环处理由命令返回的第一行之后退出,跳转到输出发现版本信息的 FINDSTR

For this task just the first line with a version information is of interest. So loop is exited with a jump to output the found version information after processing the first line returned by command findstr.

这是输出错误信息而不是版本信息,如果发生像因为在XML文件中同时改变没有连接网络服务器,或者语法没有XML文件中的错误。

An error message is output instead of the version information if an error occurred like no XML file because of no connection to web server, or syntax in XML file changed in the meantime.

有没有,如果令牌3发支票确实是引用的版本信息。因此,如果例如空格代替标签是输出的PHP脚本在服务器上缩进行批处理文件code必须更新。

There is no check made if token 3 is really referencing the version information. Therefore the batch file code must be updated if for example spaces instead of tabs are output by the PHP script on server for indenting the lines.

批code从服务器上下载,以避免解析XML旧文件之前删除XML文件。 XML文件和使用的环境变量正在退出批处理文件只是为了留下一个干净的环境恢复之前也被删除。

The batch code deletes the XML file before downloading it from server to avoid parsing an old XML file. The XML file and the used environment variable are also deleted before exiting the batch file just for leaving a clean environment back.

编辑:

用命令作为行可能还

for /F "usebackq tokens=2 delims=<   " %%V in (`%SystemRoot%\System32\findstr.exe "<title>3DS" "nintendo3dsupdate.xml" 2^>nul`) do (

有3个字符后的 delims =


  1. 尖括号&LT;

  2. 一个水平制表符的(不是空格作为浏览器的显示顺序)

  3. 一个空格字符。

分隔符字符的顺序,否则命令行间preTER重要的会退出,因为语法错误的批处理脚本。

The order of the delimiter characters is important as otherwise command line interpreter would exit batch script because of a syntax error.

缩进标签与此修改忽略。因此现在第一线被分成:

The indenting tabs are ignored with this modification. Therefore now first line is split to:


  • 标记1:标题&GT; 3DS

  • 标记2: 9.4.0-21

  • 令牌3: /标题&GT;

  • token 1: title>3DS
  • token 2: 9.4.0-21
  • token 3: /title>

和标记 2 ,而不是现在3包含感兴趣输出字符串。

And token 2 instead of 3 contains now the string of interest to output.

此解决方案比第一次更好,因为如果与版本字符串行缩进用空格或制表符或根本没有缩进它不再重要。

This solution is better than first one as it does not matter anymore if the line with the version string is indented with spaces or tabs or not indented at all.

这篇关于XMLStarlet不打印全系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆