4
votes

I'm currently trying to parse an XML, which includes another XML, using external parsed entitiy references. However, NSXMLParser throws an error instead of parsing the included XML.

The xml looks somewhat like this:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE parentElement[
<!ENTITY extern SYSTEM "myGreatURI">
]>

<parentElement
    attribute1="1" 
    attribute2="2" 
    ...>
    <childElement>

        &extern;

        <parentElement
        ..>
            <childElement>

I have enabled the parser to parse external references:

self.parser.shouldResolveExternalEntities = TRUE;

As the definition of my external entity is parsed, the according delegate method is called:

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

It passes the correct values: entityName = "extern" and systemID = "myGreatURI"

But as the reference is parsed in the xml, NSXMLParser Error 1549 occurs.


Only after this error ocurred, the expected delegate Method is called:

- (NSData *)parser:(NSXMLParser *)parser resolveExternalEntityName:(NSString *)entityName systemID:(NSString *)systemID 

But now the systemID is nil! Further, NSXMLParser does not use my returned data as expected. Instead of parsing it, the complete XML is detected as one String, handed to me through the method:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

As you can see I have several different issues. Unfortunately Google and the Apple Documentation left me clueless.

1

1 Answers

0
votes

From what I undestand, NSXMLParser always returns systemID = nil in resolveExternalEntityName, because by the time it gets here, the systemID ressource should have been loaded, and if it failed to retrieve it, it means systemID is invalid or something, so it would be useless anyways.