转换 XML to YAML
转换 XML documents to YAML for more readable configuration files. YAML's indentation-based syntax is cleaner than XML's tags for human-authored data.
- 1
XML 我们 tags 和 attributes; YAML 我们 indentation 和键: 值 pairs. Converting XML 到 YAML produces 更多 readable 格式化为 配置. Attributes 成为关键 (经常 prefixed 具有 @), 文本内容 becomes #文本键, 和 nested elements 成为 nested objects.
- 2 JSON 与 XML 互转器 →
第一转换 XML 到 JSON as 中级步骤. XML attributes 映射到 JSON 关键, 子 elements 映射到 nested objects, 和 repeated elements 映射到 arrays. 此中级 JSON 是然后 converted 到 YAML.
- 3 YAML 转换器 →
将 the intermediate JSON 转换为 YAML. YAML's syntax is more compact than JSON (no quotes for most strings, no braces/brackets) and supports comments, multi-line strings, and anchors. The result is a human-readable configuration file
- 4
- 5
Caveats: XML 到 YAML 是 lossy 为 mixed 内容 (elements 具有两者文本和 子 elements, 常见在 HTML). XML namespaces, CDATA sections, 和过程 instructions 不映射 cleanly 到 YAML. Use 此 conversion 为数据-oriented XML, 不 document-oriented XML (HTML, DocBook).
常见问题
- 是 XML 到 YAML conversion lossless?
- 为数据 XML (否 mixed 内容, 否 namespaces), 它能够是 lossless. 为 document XML (mixed 内容, attributes, namespaces), 信息是 lost 或 awkwardly mapped. Use XML 为 documents, YAML 为数据配置.
- 为什么不 转换 XML directly 到 YAML?
- Going 通过 JSON as 中级是 更多 reliable — XML-to-JSON 和 JSON-to-YAML 是 well-tested conversions. Direct XML-to-YAML converters 是更少常见和 可以处理边界情况不同. two-步骤方法是 更多 robust.