如果导入不存在,XSLT将当前插入导入
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
...
<Import Project="$(SolutionDir)BuildShared.targets" />
</Project>
Run Code Online (Sandbox Code Playgroud)
我需要它将它作为第一个节点插入
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)BuildShared.targets" />
...
...
</Project>
Run Code Online (Sandbox Code Playgroud)
template.xsl;
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="http://schemas.microsoft.com/developer/msbuild/2003">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match='@*|node()'>
<xsl:copy>
<xsl:apply-templates select='@*|node()'/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ms:Project[not(ms:Import[@Project='$(SolutionDir)BuildConfiguration.targets'])]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<Import xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Project="$(SolutionDir)BuildConfiguration.targets"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
交换导入和apply-templates行给出;
runtime error: file template.xsl line 9 element copy
Attribute nodes must be added before any child nodes to an element.
我有一个xml文件
<?xml version="1.0"?>
<preferences>
<!--General options-->
<options>
<dbHost>localhost</dbHost>
<dbUser>bwserver</dbUser>
<dbPass>bwserver</dbPass>
<dbPort>3306</dbPort>
Run Code Online (Sandbox Code Playgroud)
我如何更新值dbUser?
当我输入
xmlstarlet edit --update '/preferences/options/dbUser/' --value 123 preferences.xml
Run Code Online (Sandbox Code Playgroud)
什么都没发生.我只看到终端中的文件内容.没有触及xml文件.
<xml>
<block>
<el name="a">92346</el>
<el name="b">lorem</el>
</block>
<block>
<el name="a">89753</el>
<el name="b">ipsum</el>
</block>
</xml>
Run Code Online (Sandbox Code Playgroud)
我想<el name="c">0</el>在每个<block>Linux shell脚本中插入一个元素:
<xml>
<block>
<el name="a">92346</el>
<el name="b">lorem</el>
<el name="c">0</el>
</block>
<block>
<el name="a">89753</el>
<el name="b">ipsum</el>
<el name="c">0</el>
</block>
</xml>
Run Code Online (Sandbox Code Playgroud)
我可以使用XmlStarlet附加元素:
xmlstarlet ed -a '/xml/block/el[@name="b"]' \
--type 'elem' -n 'el' -v 0
Run Code Online (Sandbox Code Playgroud)
<el>没有name属性的元素的XPath表达式是什么?xml ed命令插入属性
吗?目前我正在编辑XML文件.当我写命令
xml ed -u "/project/version" -v "2.7.13-NEW-SNAPSHOT" pom.xml > ./pom_new.xml
Run Code Online (Sandbox Code Playgroud)
它写了新的xml文件,但是当我打开文件时,nothings在其中发生了变化.
下面是给定xml的一部分,我想编辑:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.groupID.test</groupId>
<artifactId>test-api-parent-pom</artifactId>
<version>2.7.13-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-api-parent-pom</name>
...
...
</project>
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我有以这种方式格式化的 XML 数据:
<XML>
<Waveforms Time="01/01/2009 3:00:02 AM">
<WaveformData Channel="I">1, 2, 3, 4, 5, 6 </WaveformData>
<WaveformData Channel="II">9, 8, 7, 6, 5, 4 </WaveformData>
</Waveforms>
<Waveforms Time="01/01/2009 3:00:04 AM">
<WaveformData Channel="I">1, 2, 3, 4, 5, 6 </WaveformData>
<WaveformData Channel="II">9, 8, 7, 6, 5, 4 </WaveformData>
</Waveforms>
</XML>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 xmlstarlet 将此数据解析为文本文件(逗号分隔)。所需的输出如下所示:
Time Attribute, Channel Attribute, Data
01/01/2009 3:00:02 AM, I, 1, 2, 3, 4, 5, 6
01/01/2009 3:00:02 AM, II, 9, 8, 7, 6, 5, 4
01/01/2009 3:00:02 AM, I, 1, …Run Code Online (Sandbox Code Playgroud) 这是一个相当烦人但更简单的任务。根据本指南,我写了这个:
#!/bin/bash
content=$(wget "https://example.com/" -O -)
ampersand=$(echo '\&')
xmllint --html --xpath '//*[@id="table"]/tbody' - <<<"$content" 2>/dev/null |
xmlstarlet sel -t \
-m "/tbody/tr/td" \
-o "https://example.com" \
-v "a//@href" \
-o "/?A=1" \
-o "$ampersand" \
-o "B=2" -n \
Run Code Online (Sandbox Code Playgroud)
我成功地提取从表中的每个环节和一切都被正确地连接在一起,然而,而不是再现符号为&我收到这在每一个环节的结尾:
https://example.com/hello-world/?A=1\&B=2
Run Code Online (Sandbox Code Playgroud)
但实际上,我正在寻找类似的东西:
https://example.com/hello-world/?A=1&B=2
Run Code Online (Sandbox Code Playgroud)
这个想法是使用反斜杠转义字符,\&以便它被忽略。最初,在这种情况下,我尝试将其直接放入-o "\&" \而不是-o "$ampersand" \删除ampersand=$(echo '\&')。结果还是一样。
本质上,通过删除反斜杠它仍然输出:
https://example.com/hello-world/?A=1&B=2
Run Code Online (Sandbox Code Playgroud)
只是\后面的&被删除了。
为什么?
我敢肯定这是缺少的基本知识。
我是新使用 xmlstarlet 的。我想知道如何使用 xmlstarlet 更改 xml 节点的值。
我尝试了一些东西。xmlstarlet ed --inplace -u '/file_input/uri' 'string("s3://my_source")' template.xml > output.xml
不起作用。
我的预期输出为 s3://my_source和s3://mydestination。我想更改source_path和destination_path节点。
<?xml version="1.0" encoding="UTF-8"?>
<job version="2.10.8">
<input>
<deblock_enable>Auto</deblock_enable>
<deblock_strength>0</deblock_strength>
<no_psi>false</no_psi>
<order>1</order>
<timecode_source>zerobased</timecode_source>
<file_input>
<certificate_file nil="true"/>
<password>upass</password>
<uri>source_path</uri>
<username>uname</username>
</file_input>
<file_group_settings>
<rollover_interval nil="true"/>
<destination>
<password>upass</password>
<username>uname</username>
<uri>destination_path</uri>
</destination>
</file_group_settings>
</input>
</job>
Run Code Online (Sandbox Code Playgroud)
非常感谢
我正在使用xmlstarletchangeSet从liquibase XML 变更日志中提取viewName以“v”结尾的节点。
然而,xmlstarlet 抱怨ends-withXPATH 函数不存在:
$ xmlstarlet sel -N x="http://www.liquibase.org/xml/ns/dbchangelog" -t -m \
"/x:databaseChangeLog/x:changeSet[x:createView[ends-with(@viewName, 'v')]]" \
-c . public.db.changelog.xml
xmlXPathCompOpEval: function ends-with not found
Unregistered function
Stack usage errror
xmlXPathCompiledEval: 3 objects left on the stack.
runtime error: element for-each
Failed to evaluate the 'select' expression.
None of the XPaths matched; to match a node in the default namespace
use '_' as the prefix (see section 5.1 in the manual).
For …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个公共S3存储桶中所有对象的简单清单。
我知道如何获得最多包含1000个结果的curl列表,尽管我不知道如何对结果进行分页才能获得完整列表。我认为标记是一个线索。
我不想使用SDK /库或进行身份验证。我正在寻找几行外壳程序来执行此操作。
由于我在其他地方找不到解释的示例,因此我以问答形式分享我的发现。
考虑这个学生名单(pupils.xml):
<pupils>
<pupil>
<firstName>Adam</firstName>
<lastName>Amith</lastName>
<birthDate>2000-01-01</birthDate>
</pupil>
<pupil>
<firstName>Berta</firstName>
<lastName>Bmith</lastName>
<birthDate>2000-01-02</birthDate>
</pupil>
<pupil>
<firstName>Caesar</firstName>
<lastName>Cmith</lastName>
<birthDate>2000-01-03</birthDate>
</pupil>
<pupil>
<firstName>Doris</firstName>
<lastName>Dmith</lastName>
<birthDate>2000-01-04</birthDate>
</pupil>
</pupils>
Run Code Online (Sandbox Code Playgroud)
我如何选择每个学生的两个子属性以获得如下列表:
Adam Amith
Berta Bmith
Caesar Cmith
Doris Dmith
Run Code Online (Sandbox Code Playgroud)