我正在使用libXML2读取从后端系统检索到的XML的iOS应用程序中工作。我有以下的XML,这是一个更大的XML文档的一部分:LibXML2剥离属性中的新行
<properties uiValue="This is a multiline description with text that should wrap but should also preserve any whitespace: like this whitespace.
And preserve newlines.
espace:~` [email protected]#$%^&*()_+=-<>/ \" name="desc">
<values value="This is a multiline description with text that should wrap but should also preserve any whitespace: like this whitespace.
And preserve newlines.
espace:~` [email protected]#$%^&*()_+=-<>/ \"/>
</properties>
整体而言,文档似乎解析确定。我的问题是,该新行没有被处理,所以当我读到的属性值,结果是:
This is a multiline description with text that should wrap but should also preserve any whitespace: like this whitespace. And preserve newlines. espace:~` [email protected]#$%^&*()_+=-<>/
有什么办法让这些新的生产线?如果我直接从服务器打印出响应XML,则保留新行。当我通过解析时,新的行被删除。让事情变得复杂一点,这是我正在尝试修复的一些第三方代码,而且我还没有真正使用过libXML2。相关的代码(我相信)是:
NSLog(@"Response:\n%@", [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]);
xmlDocPtr doc = xmlReadMemory([data bytes], [data length], NULL, NULL, XML_PARSE_COMPACT | XML_PARSE_NOBLANKS);
xmlNodePtr cur = ....;
xmlChar *attrValue = xmlGetProp(cur, (const xmlChar *) "uiValue");
NSString *attrString = [NSString stringWithCString:(char*)attrValue encoding:NSUTF8StringEncoding];
我曾尝试服用XML_PARSE_COMPACT和XML_PARSE_NOBLANKS的选择了,但这并没有帮助(不,我预期,我相信那些仅影响节点)。