You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XML文档报错:最终结束标签后预期起始标签问题求助

问题排查:XML文档末尾预期起始标签的错误原因

嘿,我一眼就揪出问题所在了!你遇到的xmllint报错,根源不是标签未闭合,而是这行处理指令的两处语法错误:

<?xml-stylesheet type="text/xsl" href=/Users/Andrew/Desktop/schoolwork/devicexsl.xsl> 

错误点拆解

  1. 属性值未加引号:XML规范强制要求所有属性值必须用单引号或双引号包裹,哪怕属性值里没有空格或特殊字符也不能省略。你这里的href路径裸写,导致解析器把后续内容当成处理指令的一部分,逻辑彻底混乱。
  2. 处理指令未闭合:XML处理指令的结尾必须是?>,你只写了单个>,解析器会一直等待指令结束,读到文档末尾都没找到预期的闭合标记,于是抛出了“文档末尾预期存在一个起始标签”的误导性报错。

修正后的XML代码

只需要补上引号和处理指令闭合标记即可:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="/Users/Andrew/Desktop/schoolwork/devicexsl.xsl"?> 
<device> 
 <phone> 
 <make> Apple </make> 
 <model> iPhone 12 </model> 
 <OS> iOS </OS> 
 <osVersion>14.4</osVersion> 
 <color> Blue </color> 
 <screensize> 6.1 </screensize> 
 <price>€914 </price> 
 </phone> 
 <tablet> 
 <make> Apple </make> 
 <model> iPad Air </model> 
 <OS> iOS </OS> 
 <osVersion> 14.1 </osVersion> 
 <color> Black </color> 
 <screensize> 11 </screensize> 
 <price> €700 </price> 
 </tablet> 
</device>

现在用xmllint重新检测,这个错误应该就消失啦!

内容的提问来源于stack exchange,提问作者Andrew Eckerberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 11:23:04