📄 XML to YAML Converter

📐 工作原理與說明
XML → JSON:先剔除註釋、處理指令並把 CDATA 段還原為文本;對每個元素取 < 與 > 之間的頭部,尾部為 / 判為自閉合,頭部第一個空白前為標籤名,其餘用 ([\w:-]+)\s*=\s*"([^"]*)" 提取屬性;子節點按標籤名分組,同名只有一個取單值、多個取陣列;屬性以 @ 字首放入物件,文本以 #text 鍵放入;根節點缺失或解析失敗給出錯誤提示。JSON → XML:值為物件時以 @ 字首的鍵還原為屬性、#text 還原為文本、陣列按同名元素逐個序列化;頂層鍵不止一個時外層包 <root>。YAML 標量還原規則:去成對引號,true/false 轉布林,null 與 ~ 轉空,純整數轉 parseInt、純小數轉 parseFloat,其餘保持字串;字串含 : # - [ ] { } , 或首尾有空白、以數字開頭、等於 true/false/null 時加雙引號;以 @ / # 開頭的對映鍵(如屬性 @id、文本 #text)也加雙引號以符合 YAML 1.2
把 XML 轉換為 YAML。
  • 對映:XML 的層級結構轉為 YAML 的巢狀對映,重複元素轉為序列。
  • 命名:元素名與屬性名可能衝突,需約定合併或加字首規則。
  • 縮排:YAML 依賴縮排表達層級,轉換時必須保證層級一致且只用空格。
  • 用途:配置遷移、資料交換與人工編輯場景。

XML to YAML Converter - Paste XML and convert it to YAML (attributes as @key, text as #text). Free, browser-only.

Formula & Standard References

Item Formula / Note Source / Standard
Node mapping element names as keys, children as nested mappings W3C XML 1.0 / YAML 1.2
Text and attributes text as scalar value; attributes need explicit keys YAML 1.2
Indentation YAML encodes hierarchy by indentation, must align exactly YAML 1.2
⚠️ 使用說明與注意事項