NSXMLParser foundCharacters返回“\ n”字符

时间:2011-07-22 12:25:44

标签: objective-c ios cocoa-touch nsxmlparser

我有一个xml解析器,而foundCharacters回调方法正在返回这样的字符串:

"\n     "
"\n  "

这里是我正在解析的XML部分,我在其中的任何地方都看不到这个字符串:

<GetChannelMessages xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">
  <element p2:type="ToonInDevModel.GetChannelMessagesTest_Result" xmlns:p2="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <messageid p2:type="Edm.Int32">15030</messageid>
    <userid p2:type="Edm.Int32">1</userid>
    <Handle xml:space="preserve">Henry     </Handle>
    <Distance p2:type="Edm.Double">16.845658889067568</Distance>
    <MessageDateTime p2:type="Edm.DateTime">2011-07-18T03:14:43.17</MessageDateTime>
    <Message>Posting this message again</Message>
  </element>
  <element p2:type="ToonInDevModel.GetChannelMessagesTest_Result" xmlns:p2="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <messageid p2:type="Edm.Int32">15021</messageid>
    <userid p2:type="Edm.Int32">1</userid>
    <Handle xml:space="preserve">Henry     </Handle>
    <Distance p2:type="Edm.Double">16.845658889067568</Distance>
    <MessageDateTime p2:type="Edm.DateTime">2011-07-18T01:45:17.097</MessageDateTime>
    <Message>Posting this message again</Message>
  </element>
  <element p2:type="ToonInDevModel.GetChannelMessagesTest_Result" xmlns:p2="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <messageid p2:type="Edm.Int32">15018</messageid>
    <userid p2:type="Edm.Int32">1</userid>
    <Handle xml:space="preserve">Henry     </Handle>
    <Distance p2:type="Edm.Double">16.845658889067568</Distance>
    <MessageDateTime p2:type="Edm.DateTime">2011-07-18T01:33:18.1</MessageDateTime>
    <Message>Posting this message again</Message>
  </element>

这个XML有什么问题吗?

1 个答案:

答案 0 :(得分:1)

这很正常。

“\ n”是一个换行符。 XML解析器将告诉您它找到的所有字符,甚至是元素本身之间的空格和行。