English 中文(简体)
nsxmlparser not solving '
原标题:

Im using NSXMLParser to dissect a xml package, I m receiving &apos inside the package text.

I have the following defined for the xmlParser:

[xmlParser setShouldResolveExternalEntities: YES];

The following method is never called

- (void)parser:(NSXMLParser *)parser foundExternalEntityDeclarationWithName:(NSString *)entityName publicID:(NSString *)publicID systemID:(NSString *)systemID

The text in the field before the &apos is not considered by the parser.

Im searching how to solve this, any idea???

Thanks in advance Alex

XML package portion attached:

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:appwsdl"><SOAP-ENV:Body><ns1:getObjects2Response xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"><return xsi:type="tns:objectsResult"><totalRecipes xsi:type="xsd:string">1574</totalObjects><Objects xsi:type="tns:Item"><id xsi:type="xsd:string">4311</id><name xsi:type="xsd:string"> item title 1 </name><procedure xsi:type="xsd:string">item procedure 11......
问题回答

Here is what I did, after referring a different answer from here. I replaced all the occurrences of the &apos; in the xml with " " when the data is received from NSURLConnection object. Then I give that data to the parser.

So what I do is:

NSData* parserData = [self resolveHTMLEntities: self.receivedData];
NSXMLParser* parser = [[NSXMLaParser alloc] initwithData:parserData];

Here is the resolveHTMLEntitites method:

NSString *xmlCode = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSMutableString *temp = [NSMutableString stringWithString:xmlCode];

// Replace all the entities
[temp replaceOccurrencesOfString:@"&amp;apos;" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [temp length])];

NSData *finalData = [temp dataUsingEncoding:NSUTF8StringEncoding];
return finalData;

The catch is that &apos; gets converted to &amp;apos; thats why we need to replace that occurrence.

Note: No memory management is performed in the above block of code.

Hope this helps.

The standard entities are &lt;, &gt;, &amp;, and &quot;. &apos; is an html entity reference. Does your XML refer to the XHTML namespace or some other namespace that has &apos; defined?

(BTW, would be nice to see a small segment of the XML including the header.)





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签