xml

xml 将 XML 映射为可寻址的树:元素使用点路径,属性使用 @name,元素文本使用 #text。

数据版本 1.1.6稳定
lil-terminal

概览

xml 为 XML 提供同样聚焦的流程:读取元素和属性路径,搜索键或值,原子修改一个节点,验证文档,并在需要完整内容时输出规范化 XML。

元素、属性和文本是不同节点

config.@env 与 config.application.name 指向不同 XML 节点。紧凑路径适合简单 XML,并不替代 XPath 或完整 XML 编辑器;需要 PHP DOM。

语法

lil-terminal
xml <file> [key|options] · xml dump <file>

参考

xml <file>

显示 XML 数据

xml <file> <key>

按路径显示精确的元素、属性(@name)或 #text

xml dump <file>

显示规范化的 XML 源文本

-f <text|mask> [-k|-v]

在键或值中查找匹配项;* 和 ? 表示掩码

-w <key> : <value>

写入值并规范化 XML 文件

-w <key> < <file>

写入从另一个文件读取的值

-d <key>

按点路径删除值

-c

验证 XML 文件

限制与安全

重新保存 XML 可能丢失注释、命名空间、混合内容细节、原始空白或元素顺序。禁止 DTD 和外部实体。需要 PHP DOM;Minimum 只能显示整个文件。需要保留源码格式时使用 edit 或 code。

交互式 sandbox 预览

可直接在页面中运行预先准备的示例。结果已预先生成并在浏览器中显示;服务器不会执行任何终端命令。

打开文件并通过 $ 继续使用

安装与管理

安装当前兼容版本。完整功能请选择 Base,精简包请选择 Minimum;已安装模块的更新请使用 upgrade。

Base 与 Minimum 是同一当前模块版本的两个包。

Base 包

安装包含本地参考和全部已发布模式的完整包。

install xml
Minimum 包

安装精简包。该包不包含本地参考;help <cmd> -i 会打开当前服务器参考。

install xml -m
精确公开版本

安装这个确切的已发布版本。

install xml -v 1.1.6
检查或升级

让 upgrade 检查兼容性,仅在需要时替换已安装块。

upgrade xml
删除模块

删除扩展块,不影响核心和其他模块。

install xml -u

示例

示例可复制,但网站不会执行。请先检查路径、权限和破坏性选项。

打开文件并通过 $ 继续使用
xml config/app.xml
config.@env               production
config.application.name   lil-shop
config.application.debug  true
config.database.host      localhost
config.database.port      3306
按路径显示精确的元素、属性(@name)或 #text
xml config/app.xml config.application.name
lil-shop
按路径显示精确的元素、属性(@name)或 #text
xml config/app.xml config.@env
production
按路径显示精确的元素、属性(@name)或 #text
xml config/app.xml config.database.port
3306
在键或值中查找匹配项;* 和 ? 表示掩码
xml config/app.xml -f "config.database.*" -k
config.database.host  localhost
config.database.port  3306
在键或值中查找匹配项;* 和 ? 表示掩码
xml config/app.xml -f "localhost" -v
config.database.host  localhost
在键或值中查找匹配项;* 和 ? 表示掩码
xml config/app.xml -f "debug"
config.application.debug  true
写入值并规范化 XML 文件
xml config/app.xml -w config.database.port : 3307
config.database.port  3307
写入从另一个文件读取的值
xml config/app.xml -w config.application.name < config/from-value.txt
config.application.name  new-shop
按点路径删除值
xml config/app.xml -d config.application.debug
config.@env              production
config.application.name  lil-shop
config.database.host     localhost
config.database.port     3306
处理不存在的文件
xml config/app.xml -c
Valid XML
显示规范化的 XML 源文本
xml dump config/app.xml
<?xml version="1.0" encoding="UTF-8"?>
<config env="production">
  <application>
    <name>lil-shop</name>
    <debug>true</debug>
  </application>
  <database>
    <host>localhost</host>
    <port>3306</port>
  </database>
</config>
按路径显示精确的元素、属性(@name)或 #text
xml config/app.xml unknown.key
Path not found
验证 XML 文件
xml config/invalid.xml -c
Invalid XML
显示 XML 数据
xml config/missing.xml
File not found
写入值并规范化 XML 文件
xml config/app.xml -w config.database.port
Value required after : or <
按点路径删除值
xml config/app.xml -d config
XML data must have exactly one root element
写入值并规范化 XML 文件
xml config/app.xml -w config.missing.child : 5
Parent path is not a collection

本示例使用的文件: sandbox/config/app.xml

该示例使用受保护的 /sandbox/ 文档工作区中的文件或目录。

<?xml version="1.0" encoding="UTF-8"?>
<config env="production">
  <application><name>lil-shop</name><debug>true</debug></application>
  <database><host>localhost</host><port>3306</port></database>
</config>

相关文档

当前公开版本

v1.1.62026-11-01

生产级完善

xml 的当前稳定版本。xml 将 XML 映射为可寻址的树:元素使用点路径,属性使用 @name,元素文本使用 #text。