Python XMLSyntaxError:应为开始标记,“<”未找到,第1行第1列

2024-10-03 00:31:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用lxml读取XML文件,但一直收到以下错误:

XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1

我的代码:

import lxml
parser16= lxml.etree.XMLParser(encoding = "utf-16")
tree = lxml.etree.parse(input_filepath, parser = parser16)

XML文件头:

<?xml version="1.0" encoding="utf-16"?>
<LoanResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <encompassId>b100ab9f-444-5555-949c-1873ed1ddeb3</encompassId>
  <adverseActionDate>2018-06-20T00:00:00Z</adverseActionDate>
  <applications>
    <Application>
      <id>_borrower1</id>
      <applicationId>_borrower1</applicationId>
      <applicationIndex>0</applicationIndex>
      <assets>
        <Asset>
          <id>Asset/0</id>
          <assetType>LifeInsurance</assetType>
          <borrowerId>_borrower1</borrowerId>
          <isEmpty>true</isEmpty>
        </Asset>

错误:

XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1

感谢您在解决问题时提供的任何帮助/意见


Tags: 文件idtag错误linenotcolumnxml