2009-11-20 4 views
0

xml 패키지를 해독하기 위해 NSXMLParser를 사용하고 있는데, 패키지 텍스트 내에 & apos를 받았습니다. 나는 XmlParser가 정의 다음 한nsxmlparser 해결할 수 없음 '

은 :

[xmlParser setShouldResolveExternalEntities: YES]; 

다음 방법을 파서 고려하지 않는 & APOS 전에 필드의 텍스트

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

를 호출되지 않습니다.

나는 이것을 해결하는 방법을 검색하는 Im, 어떤 생각 ???

덕분에 사전에 알렉스

XML 패키지 부분은 첨부 :

<?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...... 

답변

0

표준 기관은 &lt;, &gt;, &amp;&quot; 있습니다. &apos;은 html 엔티티 참조입니다. XML이 XHTML 네임 스페이스 또는 &apos;이 정의 된 다른 네임 스페이스를 참조합니까?

(BTW, 헤더를 포함한 XML의 작은 세그먼트를 볼 것이 좋을 것이다.)

여기
+0

나는 XML 부분을 atached했고, 파서는 & amp;와 함께 당신에게 많은 도움을 주었다. – alex

+0

필자는 Mac을 사용하지 않으므로 테스트를 실행할 수 없지만'foundInternalEntityDeclarationWithName'을 시도해 보셨습니까? –

+0

예, 모든 엔티티 관련 대리자를 시도했지만 아무도 호출되지 않았습니다. ( 감사합니다. 엡실론 :) – alex

1

내가 여기에서 다른 대답을 참조 후, 한 일이다. NSURLConnection 개체에서 데이터를 수신 할 때 xml의 &apos;이 모두 "'"으로 바뀌 었습니다. 그런 다음 해당 데이터를 파서에 전달합니다.

그래서 내가 할 것입니다 :

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; 

캐치 우리가 그 발생을 교체해야하는 이유 &apos;&amp;apos; 그게 전부로 변환됩니다 있다는 것입니다 :

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

가 resolveHTMLEntitites 방법입니다.

참고 : 위 코드 블록에서는 메모리 관리가 수행되지 않습니다.

희망이 도움이됩니다.