我正在使用命令:
xmlstarlet ed --omit-decl --subnode "/boinc" --type elem -n app -v "" project_00.xml > project_01.xml
但是,我想在这一个中再插入两个标签:
<app>
<name>name</name>
<nikname>nikname</nikname>
</app>
Run Code Online (Sandbox Code Playgroud)
在我project_00.xml,我已经有其他标签应用程序,它导致冲突.
此命令的问题:
xmlstarlet ed --subnode "/boinc" --type elem -n app -v "" project_00.xml| xmlstarlet ed --subnode //app --type elem -n name -v "newApp"| xmlstarlet ed --subnode //app --type elem -n user_friendly_name -v "New.App" > project_01.xml
Run Code Online (Sandbox Code Playgroud)
就是它创造了这个:
<app name="wilson">
<name>wilson</name>
<user_friendly_name>Mr.Wilson</user_friendly_name>
<name>newApp</name>
<user_friendly_name>New.App</user_friendly_name>
</app>
<app>
<name>newApp</name>
<user_friendly_name>New.App</user_friendly_name>
</app>
Run Code Online (Sandbox Code Playgroud)
知道确切的命令吗?
我尝试了这个命令,但它复制了所有应用程序标签
xmlstarlet ed -s "/boinc" -t elem -n app -v …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的XML文件,我需要用xmlstarlet解析(我在Windows下):
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<pain.001.001.02>
<GrpHdr>
<MsgId>IDENTIFYER</MsgId>
<CreDtTm>2013-01-25T11:15:02</CreDtTm>
<NbOfTxs>6</NbOfTxs>
<CtrlSum>6268.07</CtrlSum>
<Grpg>MIXD</Grpg>
</GrpHdr>
<PmtInf>
</PmtInf>
</pain.001.001.02>
</Document>
Run Code Online (Sandbox Code Playgroud)
假设我想要检索CtrlSum元素; 我尝试时失败了
xml sel -t -m "/Document/pain.001.001.02/GrpHdr" -v CtrlSum myfile.xml
Run Code Online (Sandbox Code Playgroud)
但是如果我从文件中删除xmlns和xmlns:xsi属性它可以工作(但我不能在现实生活中这样做).我知道我必须使用-N选项,但我无法想象如何做到这一点.任何帮助都是非常有价值的.
非常感谢Laurent(或Lawrence,或Larry :))
我有这个xml模式,我想要的是如何使用XMLStarlet在shell脚本中一个接一个地提取所有节点的值
<service>
<imageScroll>
<imageName>Photo_Gallerie_1.jpg</imageName>
</imageScroll>
<imageScroll>
<imageName>Photo_Gallerie_2.jpg</imageName>
</imageScroll>
<imageScroll>
<imageName>Photo_Gallerie_3.jpg</imageName>
</imageScroll>
</service>
Run Code Online (Sandbox Code Playgroud) 我有一个XML文档,我想使用XMLStarlet从所有元素(或给定类型的所有元素)中删除某种类型的所有属性及其值,而不会干扰其他属性.
例如,我想bad从任何a元素中删除所有属性:
<root>
<a href="." bad="yes"/>
<a bad=""/>
</root>
Run Code Online (Sandbox Code Playgroud)
变
<root>
<a href="."/>
<a/>
</root>
Run Code Online (Sandbox Code Playgroud) 如何过滤掉某些类型的元素,这些元素没有具有魔术值的属性并保留文档的其余部分?所有这些使用xmlstarlet?
我到底要做的是:
cat << EOF > database.xml
<?xml version="1.0"?>
<database>
<some name="A" />
<some name="B" />
<some name="C" />
<text>this is some text to be applied...</text>
<project>
<test deeper="structure"/>
</project>
</database>
EOF
Run Code Online (Sandbox Code Playgroud)
和
xmlstarlet sel -t -m "*" -c "*[not(self::some[@name != 'A'])]" database.xml
Run Code Online (Sandbox Code Playgroud)
产量
<some name="A"/><text>this is some text to be applied...</text><project>
<test deeper="structure"/>
</project>
Run Code Online (Sandbox Code Playgroud)
但这隐藏了我的宝贵<database> tag.除了缩进,这不是一个问题...并且当<some>不是例如<database>孩子的直接后裔时不起作用<project>.
我想是数据库,因为它是,但都<some>删除,除了指定的一个A:
<database>
<some name="A" /> …Run Code Online (Sandbox Code Playgroud) 在网页上使用xmlstarlet时,我大部分时间都面临实体引用错误.这使得它无法从网页中提取.
因为html页面不是很好的形成XML(还有一些处理html的选项吗?)我将它们转换为
tidy -asxhtml
Run Code Online (Sandbox Code Playgroud)
到XHTML,其中整齐的声明
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Run Code Online (Sandbox Code Playgroud)
然后用xmlstarlet处理它
curl http://www.xfree86.org/current/index.html | tidy -asxhtml | \
xmlstarlet sel --net -T -t -m hr -v . -
Run Code Online (Sandbox Code Playgroud)
它总是抛出相同的错误
-:13: parser error : Entity 'reg' not defined
<h1>Documentation for XFree86® version 4.8.0</h1>
Run Code Online (Sandbox Code Playgroud)
有人知道如何让xmlsttarlet知道实体引用文件.
使用xmlstarlet/xpath,如何获取某个节点的所有子元素的名称?比如我想获取所有的子元素名称/a
<a>
<b><c/></b>
<d/>
</a>
Run Code Online (Sandbox Code Playgroud)
应该返回:
b
d
Run Code Online (Sandbox Code Playgroud)
我试过
xmlstarlet sel -t -c 'name(/a/*)' -
Run Code Online (Sandbox Code Playgroud)
但这只给了我b
我有FramesList.txt,该文件包含5个.xml文件名.没有生成路径,因为列表是由xml ls > FramesList.txt命令创建的.
我想xmlstarlet在.xml列出的每个文件上运行命令.
FramesList.txt
FR0391W.xml
FR0921S.xml
FR0193A.xml
FR0192B.xml
FR0132E.xml
Run Code Online (Sandbox Code Playgroud)
那怎么样?这是一个循环吗?
我有一个脚本正在向我的 XML 文件添加一个子节点,并且它工作正常。
问题是我运行这个脚本很多时间,我只想添加我的子节点一次,所以我需要的是检查它是否存在,如果它不存在,我想创建它,如果它不执行任何操作。(在我的示例中创建名为 66.66.66 的子节点)
#!/bin/bash
LOCK_BRANCH="66.66.66"
#Adding a new subnode to certain nodes
xmlstarlet ed -L --subnode "/configurations/rules" --type elem -n rule config.xml
#Adding text to the new node
xmlstarlet ed -L --subnode "/configurations/rules/rule[last()]" --type elem -n name -v "$LOCK_BRANCH" config.xml
xmlstarlet ed -L --subnode "/configurations/rules/rule[last()]" --type elem -n repo -v "mqm" config.xml
xmlstarlet ed -L --subnode "/configurations/rules/rule[last()]" --type elem -n branch -v "refs/heads/12.55.99" config.xml
xmlstarlet ed -L --subnode "/configurations/rules/rule[last()]" --type elem -n emailTo -v "imichael@gmail.com" config.xml
xmlstarlet …Run Code Online (Sandbox Code Playgroud)