Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload