TBXML root element is null no matter what I do
Wracking my brain for hours trying to figure this one out. TBXML must have the rootXMLElement
set in order to begin traversing and parsing data.
No matter what I do, when I NSLog
it, it's null.
Here's a sample of the 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>Gar开发者_运维百科y</nameFirst>
<!--more properties of a patient-->
</patient>
</patients>
The code I'm using thus far:
NSURL *xmlURL = [NSURL URLWithString:destPath];
TBXML *tbxml = [TBXML tbxmlWithURL:xmlURL];
NSLog shows tbxml.rootXMLElement
as null.
Other details of note:
- I use a ruby script to delete any non-ASCII characters from the XML file. The app does not require anything more.
- I thought the problem might be that the XML file was not UTF-8, so I used bash command
iconv
to convert it from ASCII to UTF-8. Didn't work either.
Any suggestions are greatly appreciated.
It looks like it is a local XML based on the fact that you are preprocessing it. When you are processing local file paths as URLs you need to use fileURLWithPath:
for it to work properly. So you need to do this,
NSURL *xmlURL = [NSURL fileURLWithPath:destPath];
TBXML *tbxml = [TBXML tbxmlWithURL:xmlURL];
精彩评论