XML解析:如何忽略空格或输入/返回空格 [英] XML Parsing: how to ignore whitespace or enter/return space

查看:55
本文介绍了XML解析:如何忽略空格或输入/返回空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满项目的在线xml文件.

i have an online xml file filled with items.

在启动时,我检查我的Internet连接,如果是,我将解析xml并将项目对象与sqlite数据库中的对象进行比较.项目值之一是"lastupdated",这是一个由php生成的字符串.

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.

如果xml项目中的lastupdated值与数据库中的值不同,则需要将该项目更新到数据库中.

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.

我似乎有解析错误:因为数据库中的lastupdated值有10个字符,而xml文件中的lastupdated值似乎有11个字符.当我同时输出两者时,得到以下信息:

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] 12694291662010-03-26 15:15:07.771 bbc_v1 [97647:207]12694291662010-03-26 15:15:07.771 bbc_v1 [97647:207]长度xml项目值:112010-03-26 15:15:07.771 bbc_v1 [97647:207]长度db值:10

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

看来我在解析空格和输入/返回内容时遇到问题?我应该如何清除xml值?

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

推荐答案

尝试使用 -stringByTrimmingCharactersInSet 函数:

NSString* cleanString = [dirtyString stringByTrimmingCharactersInSet:
                          [NSCharacterSet whitespaceAndNewlineCharacterSet]];

这篇关于XML解析:如何忽略空格或输入/返回空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆