繁体   English   中英

从终端到Windows Powershell的Xmlstarlet命令

[英]Xmlstarlet command from terminal to Windows Powershell

在我的终端(linux / mac)上,我使用以下命令:

xmlstarlet ed -N ns=http://www.w3.org/2006/04/ttaf1 -d //ns:div[not(contains(@xml:lang,'Italian'))] "C:\Users\1H144708H\Downloads\a.mul.ttml" > "C:\Users\1H144708H\Downloads\a.mul.ttml.conv"

在Windows(PowerShell)上,我真的不知道如何修复此命令。 我知道我需要使用$而不是@(因为powershell表示使用$而不是@),但是contains出了点问题:

./xml.exe ed -N ns=http://www.w3.org/2006/04/ttaf1 -d //ns:div[not(contains($xml:lang,'Italian'))] "C:\Users\1H144708H\Downloads\a.mul.ttml" > "C:\Users\1H144708H\Downloads\a.mul.ttml.conv"

我什至尝试了这个:

./xml.exe ed -N ns=http://www.w3.org/2006/04/ttaf1 -d //ns:div[not($xml:lang -contains'Italian')] "C:\Users\1H144708H\Downloads\a.mul.ttml" > "C:\Users\1H144708H\Downloads\a.mul.ttml.conv"

但是我得到“无法加载外部实体“ False””

//ns:div[not(contains(@xml:lang,'Italian'))]是一个XPath表达式,其中包含一些各种shell特有的字符,因此应使用引号将其保护。 在bash,Powershell和cmd.exe中使用双引号可以工作:

xmlstarlet ed -N ns=http://www.w3.org/2006/04/ttaf1 -d "//ns:div[not(contains(@xml:lang,'Italian'))]" "C:\Users\1H144708H\Downloads\a.mul.ttml" > "C:\Users\1H144708H\Downloads\a.mul.ttml.conv"

使用bash或Powershell时,最好使用单引号。 对于那些外壳,需要这样做以防止$扩展(尽管在XPath中使用此功能相当先进):

xmlstarlet ed -N ns=http://www.w3.org/2006/04/ttaf1 -d '//ns:div[not(contains(@xml:lang,"Italian"))]' "C:\Users\1H144708H\Downloads\a.mul.ttml" > "C:\Users\1H144708H\Downloads\a.mul.ttml.conv"

注意,内部引号也需要交换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM