XML Parsing: how to ignore whitespace or enter/ret

2019-05-30 04:22发布

i have an online xml file filled with items.

At startup i check my internet connection, if so, i parse the xml and compare the item objects to those in my sqlite database. One of the item values is 'lastupdated', whichs is a php generated string.

if the lastupdated value from the xml item is different from the value of the one in the database, the item needs to be updated into the database.

I seem to have parsing errors: as the lastupdated value in my database has 10 characters, and the one in my xml file seems to have 11.. When I output both i get the following:

2010-03-26 15:15:07.771 bbc_v1[97647:207] 1269429166 2010-03-26 15:15:07.771 bbc_v1[97647:207] 1269429166 2010-03-26 15:15:07.771 bbc_v1[97647:207] lenght xml item value: 11 2010-03-26 15:15:07.771 bbc_v1[97647:207] length db value: 10

it seems i'm having parsing problems with whitespace and enter/return stuff? How should I clean the xml value?

2条回答
来,给爷笑一个
2楼-- · 2019-05-30 05:10

What about running strip or trim on the string. This normally eliminates whitespaces.

查看更多
冷血范
3楼-- · 2019-05-30 05:24

Try the -stringByTrimmingCharactersInSet function:

NSString* cleanString = [dirtyString stringByTrimmingCharactersInSet:
                          [NSCharacterSet whitespaceAndNewlineCharacterSet]];
查看更多
登录 后发表回答