我正在使用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的選擇了,但這並沒有幫助(不,我預期,我相信那些僅影響節點)。