我需要编辑一些 XML 文件,我可以删除和设置,但我不知道是否以及如何仅使用 Augeas 对 XML 文件进行排序?
有没有人这样做过,我现在正试图避免使用除 Augeas 之外的其他资源?
我正在使用 puppet、ruby、shell 脚本。我可以在 puppet 中使用 augeas,而不仅仅是 augtool。
这是我的确切任务:按元素名称、属性名称、表和列对元素进行排序
我有一个很大的 XML 文件,它实际上包含很多表,这是一个表的示例:
<table name="validation_rule" numRows="6" remarks="" schema="public" type="TABLE">
<column autoUpdated="false" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="int4">
<child column="validation_rule_id" foreignKey="meta_field_name_validation_rule_id_fkey" implied="false" onDeleteCascade="false" table="meta_field_name"/>
<child column="validation_rule_id" foreignKey="preference_type_validation_rule_id_fkey" implied="false" onDeleteCascade="false" table="preference_type"/>
<child column="validation_rule_id" foreignKey="validation_rule_attributes_validation_rule_id_fkey" implied="false" onDeleteCascade="false" table="validation_rule_attributes"/>
</column>
<column autoUpdated="false" digits="0" id="1" name="rule_type" nullable="false" remarks="" size="25" type="varchar"/>
<column autoUpdated="false" digits="0" id="2" name="enabled" nullable="true" remarks="" size="1" type="bool"/>
<column autoUpdated="false" digits="0" id="3" name="optlock" nullable="false" remarks="" size="10" type="int4"/>
<primaryKey column="id" sequenceNumberInPK="1"/>
<index name="validation_rule_pkey" unique="true">
<column ascending="true" name="id"/>
</index>
</table>
这就是我从同一个示例文件中删除的方式:
augtool> set /augeas/load/xml/lens "Xml.lns"
augtool> set /augeas/load/xml/incl /home/ESSENT/i.camilovic/test/test.xml
augtool> load
augtool> rm /files/home/ESSENT/i.camilovic/test/test.xml/TopLevel/FooBar
augtool> save
这是 puppet 中的代码示例,我们用于其他用途:
augeas { "${name} ReverseBuild Threshold fails":
lens => 'Xml.lns',
incl => $config_file,
context => "${context}/triggers/jenkins.triggers.ReverseBuildTrigger/threshold",
changes => [
"set name/#text 'FAILURE'",
"set ordinal/#text '2'",
"set color/#text 'RED'",
"set completeBuild/#text 'true'",
],
notify => Exec['reload-configuration'],
require => Augeas["${name} Upstream Projects"],
}