AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[xml](unix)

Martin Hope
Ashark
Asked: 2023-05-05 07:43:05 +0800 CST

如何从 fb2 书籍中提取目录?

  • 5

我有一本 fb2 格式的书。我想打印目录,其中包含“部分”、“章节”、“剧集”等的名称和编号。

有没有办法可以从终端执行此操作?有一个类似的问题,但对于 epub 格式。

我知道 fb2 是一种 xml 格式。但是有没有一种工具可以只提取TOC?它们在标签<section>,<title>和内<subtitle>。

如果没有,我想可以根据官方的FB2_to_txt.xsl文件制作 xsl 文件。也许ebook-convert可以做到这一点?

我正在写的书具有以下结构:

<?xml version="1.0" encoding="utf8"?>
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
  <description>
    <title-info>
      <genre>fiction</genre>
      <author>
        <first-name>John</first-name>
        <last-name>Doe</last-name>
      </author>
      <book-title>Fiction Book</book-title>
      <annotation>
        <p>Hello</p>
      </annotation>
      <keywords>john, doe, fiction</keywords>
      <date value="2011-07-18">18.07.2011</date>
      <coverpage></coverpage>
      <lang>en</lang>
    </title-info>
    <document-info>
      <author>
        <first-name></first-name>
        <last-name></last-name>
        <nickname></nickname>
      </author>
      <program-used>Fb2 Gem</program-used>
      <date value="2011-07-18">18.07.2011</date>
      <src-url></src-url>
      <src-ocr></src-ocr>
      <id></id>
      <version>1.0</version>
    </document-info>
    <publish-info>
    </publish-info>
  </description>
  <body>
    <title>
      <p>John Doe</p>
      <empty-line/>
      <p>Fiction Book</p>
    </title>
    <section>
      <title>
        <p>Part 1</p>
        <p>Some name of Part 1</p>
      </title>
      <section>
        <title>
          <p>Chapter 1</p>
          <p>Some name of Chapter 1</p>
        </title>
        <subtitle>Episode 1</subtitle>
        <p>Line one of the first episode</p>
        <p>Line two of the first episode</p>
        <p>Line three of the first episode</p>
        <subtitle>Episode 2</subtitle>
        <p>Line one of the second episode</p>
        <p>Line two of the second episode</p>
        <p>Line three of the second episode</p>
      </section>
    </section>
    <section>
      <title>
        <p>Part 2</p>
        <p>Some name of Part 2</p>
      </title>
      <section>
        <title>
          <p>Chapter 3</p>
          <p>Some name of Chapter 3</p>
        </title>
        <subtitle>Episode 3</subtitle>
        <p>Line one of the third episode</p>
        <p>Line two of the third episode</p>
        <p>Line three of the third episode</p>
        <subtitle>Episode 4</subtitle>
        <p>Line one of the fourth episode</p>
        <p>Line two of the fourth episode</p>
        <p>Line three of the fourth episode</p>
      </section>
    </section>
  </body>
</FictionBook>

我想在输出中获得以下内容:

Part 1
Some name of Part 1
Chapter 1
Some name of Chapter 1
Episode 1
Episode 2
Part 2
Some name of Part 2
Chapter 3
Some name of Chapter 3
Episode 3
Episode 4
xml
  • 3 个回答
  • 40 Views
Martin Hope
Mévatlavé Kraspek
Asked: 2023-02-28 16:33:04 +0800 CST

'xmlstarlet edit' 使用变量作为 XPath

  • 8

当您遵循文档时:

xmlstarlet edit --help

您可以阅读--var可用于将 XPath 表达式声明为变量的内容。

生成moc文件:

cat<<EOF > /tmp/file.xml
<root>
<elt>x</elt>
<!-- comment -->
<elt>y</elt>
<!-- other comment -->
</root>
EOF

这个有效,没有变量:

xmlstarlet edit \
    --var xp '//elt/following::comment()' \
    -a '//elt/following::comment()' -t elem -n p -v 'some new text' \
    -a '//elt/following::comment()' -t elem -n p -v 'some other text' \
/tmp/file.xml

这个不使用变量进行编辑:

xmlstarlet edit \
    --var xp '//elt/following::comment()' \
    -a xp -t elem -n p -v 'some new text' \
    -a xp -t elem -n p -v 'some other text' \
/tmp/file.xml

使用变量我想念什么?

xml
  • 1 个回答
  • 78 Views
Martin Hope
XMLnewbie
Asked: 2023-02-15 14:07:43 +0800 CST

来自两个兄弟姐妹的 xmlstarlet 中的总和值?

  • 9

我正在使用xmlstarlet从具有特定前置兄弟事件的元素中提取文本。来自 XML 文件的示例:

 <event type='cue' units='sec'>
    <onset>11.134</onset>
    <duration>0.2</duration>
    <value name='side'>CUER</value>
  </event>
  <event type='target' units='sec'>
    <onset>11.367</onset>
    <duration>1.26</duration>
    <value name='side'>TARGETR</value>
    <value name='RT' units='msec'>379</value>
    <value name='TargCorr'>1</value>
    <value name='feedback'>YOU WIN!</value>
  </event>
  <event type='anticipation' units='sec'>
    <onset>12.651</onset>
    <duration>2.65</duration>
    <value name='TargCorr'>1</value>
    <value name='feedback'>YOU WIN!</value>
  </event>

从示例中,我需要执行以下操作:

  1. 打印的onset,<event type='target'和
  2. duration打印的<event type='target'和紧随duration其后的总和<event type='anticipation'。

onset我可以使用选项打印正确的"preceding-sibling":

xmlstarlet sel -t \
 -m '//event[@type="anticipation" and value[@name="feedback"]="YOU WIN!"]' \
 -m 'preceding-sibling::event[@type="target" and value[@name="feedback"]="YOU WIN!"][1] ' \
 -v 'onset' -o ' ' -v 'duration' -o ' ' -o '1' -n $DIR/$xml \
   > $DIR/output.stf

尽管如上所写,但以下代码仅显示匹配元素的持续时间,而不是两个相邻事件的持续时间之和。后者可以使用 xmlstarlet 吗?

感谢您的帮助!

xml
  • 1 个回答
  • 62 Views
Martin Hope
caduceus
Asked: 2023-01-21 12:41:54 +0800 CST

如何按属性对 XML 元素进行排序?

  • 6

我如何对这个 XML 进行排序?

  1. 首先按字母顺序排列:module之前property。
  2. 然后按字母顺序命名属性:<module name="ClassTypeParameterName"/>before <module name="PackageName"/>。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <property name="severity" value="error"/>
  <property name="fileExtensions" value="java"/>
  <module name="NewlineAtEndOfFile"/>
  <module name="FileTabCharacter"/>
  <module name="TreeWalker">
    <module name="PackageName"/>
    <module name="ClassTypeParameterName"/>
    <module name="InterfaceTypeParameterName"/>
    <module name="MethodTypeParameterName"/>
    <module name="LambdaParameterName"/>
    <module name="PatternVariableName"/>
    <module name="RecordComponentName"/>
    <module name="RecordTypeParameterName"/>
    <module name="TypeName">
      <property name="format" value="^[A-Z][_a-zA-Z0-9]*$"/>
    </module>
    <module name="AvoidDoubleBraceInitialization"/>
    <module name="AvoidNoArgumentSuperConstructorCall"/>
    <module name="OneTopLevelClass"/>
    <module name="OuterTypeFilename"/>
  </module>
</module>

我想xq按这里的用法使用:Sorting an XML file in UNIX with a Bash script?

xml
  • 1 个回答
  • 51 Views
Martin Hope
bash_noob
Asked: 2022-06-20 16:33:37 +0800 CST

我需要一个 bash 脚本,用 0 替换文件中两个箭头之间的每个数字

  • 0

该文件的名称是 types.xml,列出了数百个不同的项目。

这是它的样子:

    <type name="CanisterGasoline">
        <nominal>50</nominal>
        <lifetime>28800</lifetime>
        <restock>0</restock>
        <min>30</min>
        <quantmin>-1</quantmin>
        <quantmax>-1</quantmax>
        <cost>100</cost>
        <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/>
        <category name="tools"/>
        <tag name="shelves"/>
        <usage name="Industrial"/>
    </type>
    <type name="Canteen">
        <nominal>20</nominal>
        <lifetime>14400</lifetime>
        <restock>0</restock>
        <min>10</min>
        <quantmin>10</quantmin>
        <quantmax>90</quantmax>
        <cost>100</cost>
        <flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/>
        <category name="food"/>
        <usage name="Military"/>
    </type>

基本上,无论它说<nominal>20</nominal>什么,我都想将介于<nominal>和之间的数字更改</nominal>为 0。

感谢您抽出宝贵的时间!

xml
  • 3 个回答
  • 35 Views
Martin Hope
Joey
Asked: 2022-06-19 02:30:44 +0800 CST

如何仅显示 XML 文件中开始和结束标记之间的内容?

  • 0

如何使用 grep 或类似方法在 XML 文件中搜索特定标签,但仅显示开始标签和结束标签之间的内容?这是我想找到的确切标签:

<max-diskusage>1024000000</max-diskusage>

但我只想得到 1024000000 部分而不是标签。

这是一个以字节为单位的存储大小,并将其转换为 1 gb IF POSSIBLE 或任何转换为​​ GB 的结果。

xml numeric-data
  • 1 个回答
  • 16 Views
Martin Hope
Matt5
Asked: 2022-05-08 02:19:33 +0800 CST

如何在 XML 文件中取消标记嵌入在指定标记中的标记字符链

  • 2

在 XML 文件中取消标记嵌入在指定标记中的标记字符链的 xmlstarlet 命令是什么?

示例:搜索每个出现的 tag <b>,只有在 tag 内才需要删除<c> ... </c>:

  • 输入示例:
    <c>This is <b>an example</b>. <a>This is <b>a test;</b></a></c>
    
  • 期望的输出:
    <c>This is an example. <a>This is <b>a test;</b></a></c>
    

为了概括起见,我保留示例中的第二句话,即

<a>This is <b>a test;</b></a>

但如果这是一个问题,则可以忽略。

text-processing xml
  • 1 个回答
  • 62 Views
Martin Hope
Matt5
Asked: 2022-05-07 04:05:56 +0800 CST

如何在 XML 文件中重命名嵌入在某些其他特定标签中的特定标签

  • 3

什么是 xmlstarlet 命令将一个标签值替换为另一个标签值,仅适用于嵌入在其他指定标签中的指定标签?

示例:搜索 tag 的每次出现,仅当它在tag 内(在其他标签内)时才b需要替换:d<a> ... </a>

  • 输入示例:
    <c>This is <b>an example</b>. <a>This is <b>a test;</b></a></c>
    
  • 期望的输出:
    <c>This is <b>an example</b>. <a>This is <d>a test;</d></a></c>
    

这篇文章与如何在 XML 文件中将某些指定标签中的特定字符串替换为我试图找到的解决方案中嵌入标签中的其他字符串以格式化 xml 文件有关。

text-processing xml
  • 1 个回答
  • 252 Views
Martin Hope
Matt5
Asked: 2022-04-25 03:29:53 +0800 CST

如何在 XML 文件中将某些指定标签中的特定字符串替换为嵌入在标签中的其他字符串

  • 2

我需要在 XML 文件中将某些指定标签中的特定字符串替换为嵌入在标签中的其他字符串。

搜索每次出现的示例,仅当它在标签内(在其他标签内)时才an example需要替换:<b>a test</b><a> ... </a>

  • 输入示例:
    <c>This is an example. <a>This is an example;</a></c>
    
  • 期望的输出:
    <c>This is an example. <a>This is <b>a test;</b></a></c>
    
text-processing xml
  • 1 个回答
  • 981 Views
Martin Hope
Alfador
Asked: 2022-03-30 06:32:20 +0800 CST

使用 awk 或 sed 更改 XML 标记的值

  • -1

所以我有一个 XML 文件

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>platform</artifactId>
        <groupId>com.test.aem</groupId>
        <version>6.1.1-SNAPSHOT</version>
    </parent>

我想将 的值更新为version新值

        <version>6.5.0-SNAPSHOT</version>

但我想确保它仅在本<parent>节中更新,而不是文件中的其他任何地方。这可能使用bash吗?

遗憾的是我不能使用xmlstarlet,因为它不包含在容器中。

text-processing xml
  • 2 个回答
  • 266 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve