I have an XML file that uses internally-declared entities. For example:
<?xml version="1.0" encoding="UTF-8"?>
...
<!ENTITY my_symbol "my symbol value">
...
<my_element>
<my_next_element>foo&my_symbol;bar</my_next_element>
</my_element>
...
Using the NSXMLParser class, how am I able to resolve the my_symbol
entity reference?
From experimentation, the parser:foundInternalEntityDeclarationWithName:value:
delegate method will be called for the my_symbol
entity declaration, with value "my symbol value"
. Then, when the my_next_element
element is reached, NSXMLParser
will call the parser:didStartElement:namespaceURI:qualifiedName:attributes:
delegate method.
Before parser:didEndElement:namespaceURI:qualifiedName:
is called for </my_next_element>
, the parser:foundCharacters:
delegate method will be called twice with the strings:
"foo"
"bar"
The my_symbol
entity reference is ignored. What is required in order for the entity reference to be resolved?
EDIT:
Removing the ENTITY
declaration of my_symbol
from the DTD will result in an NSXMLParserUndeclaredEntityError
. This suggests that when the entity declaration is present, and then referenced in <my_next_element>
, it is being noticed. For some reason it's just not being resolved to the string it represents.
Also, if &
is used within an element, the parser will correctly resolve it to "&"
and this is passed as the string when the parser:foundCharacters:
delegate method is called.