← 返回
效率工具 中文

XML

Parse, generate, and transform XML with correct namespace handling and encoding.
解析、生成和转换 XML,正确处理命名空间和编码。
ivangdavila
效率工具 clawhub v1.0.0 1 版本 99871.5 Key: 无需
★ 2
Stars
📥 1,515
下载
💾 85
安装
1
版本
#latest

概述

Namespaces

  • XPath /root/child fails if document has default namespace—use //*[local-name()='child'] or register prefix
  • Default namespace (xmlns="...") applies to elements, not attributes—attributes need explicit prefix
  • Namespace prefix is arbitrary— and are identical if both prefixes map to same URI
  • Child elements don't inherit parent's prefixed namespace—each must declare or use prefix explicitly

Encoding

  • must match actual file encoding—mismatch corrupts non-ASCII
  • Encoding declaration must be first thing in file—no whitespace or BOM before it (except UTF-8 BOM allowed)
  • Default encoding is UTF-8 if declaration omitted—but explicit is safer across parsers

Escaping & CDATA

  • Five entities always escape in text: & < > " '
  • CDATA sections for blocks with many special chars—but ]]> inside CDATA breaks it
  • Attribute values: use " if delimited by ", or ' if delimited by '
  • Numeric entities < and < work everywhere—useful for edge cases

Whitespace

  • Whitespace between elements is preserved by default—pretty-printing adds nodes that may break processing
  • xml:space="preserve" attribute signals whitespace significance—but not all parsers respect it
  • Normalize-space in XPath: normalize-space(text()) trims and collapses internal whitespace

XPath Pitfalls

  • //element is expensive—traverses entire document; use specific paths when structure is known
  • Position is 1-indexed: [1] is first, not [0]
  • text() returns direct text children only—use string() or . for concatenated descendant text
  • Boolean in predicates: [@attr] tests existence, [@attr=''] tests empty value—different results

Structure

  • Self-closing and empty are semantically identical—but some legacy systems choke on self-closing
  • Comments cannot contain --—will break parser even inside string content
  • Processing instructions cannot have ?> in data
  • Root element required—document with only comments/PIs and no element is invalid

Validation

  • Well-formed ≠ valid—parser may accept structure but fail against schema
  • DTD validates but can't express complex constraints—prefer XSD or RelaxNG for new projects
  • XSD namespace xmlns:xs="http://www.w3.org/2001/XMLSchema" commonly confused with instance namespace

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 00:31 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

productivity

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 440 📥 148,004
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,362 📥 318,920
productivity

Weather

steipete
获取当前天气和预报(无需API密钥)
★ 446 📥 226,416