gpt4 book ai didi

iphone - 无论我做什么,TBXML 根元素都是空的

转载 作者:行者123 更新时间:2023-11-29 11:21:48 25 4
gpt4 key购买 nike

绞尽脑汁想弄清楚这个问题。 TBXML 必须设置 rootXMLElement 才能开始遍历和解析数据。

无论我做什么,当我NSLog 它时,它都是空的。

这是 XML 的示例:

<?xml version= "1.0" encoding="UTF8"?> 
<patients>
<patient>
<patientNumber>1234</patientNumber>
<nameFirst>Jason</nameFirst>
<!--more properties of a patient-->
</patient>
<patient>
<patientNumber>5542</patientNumber>
<nameFirst>Gary</nameFirst>
<!--more properties of a patient-->
</patient>
</patients>

到目前为止我使用的代码:

NSURL *xmlURL = [NSURL URLWithString:destPath];
TBXML *tbxml = [TBXML tbxmlWithURL:xmlURL];

NSLog 显示 tbxml.rootXMLElement 为空。

其他注意事项:

  1. 我使用 ruby​​ 脚本从 XML 文件中删除任何非 ASCII 字符。该应用程序不再需要任何东西。
  2. 我认为问题可能是 XML 文件不是 UTF-8,所以我使用 bash 命令 iconv 将它从 ASCII 转换为 UTF-8。也没用。

非常感谢任何建议。

最佳答案

根据您正在对其进行预处理的事实,它看起来像是一个本地 XML。当您将本地文件路径作为 URL 处理时,您需要使用 fileURLWithPath: 才能正常工作。所以你需要这样做,

NSURL *xmlURL = [NSURL fileURLWithPath:destPath];
TBXML *tbxml = [TBXML tbxmlWithURL:xmlURL];

关于iphone - 无论我做什么,TBXML 根元素都是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6686502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com