菜鸟教程小白 发表于 2022-12-11 20:20:40

iphone - TouchXML 命名空间解析?


                                            <p><p>我正在尝试通过 TouchXML 解析以下 XML:</p>

<pre><code>&lt;s:Envelope xmlns:s=&#34;namespace_1&#34;&gt;
   &lt;s:Body&gt;
      &lt;DefinedEntitiesResponse xmlns=&#34;namespace_2&#34;&gt;
         &lt;DefinedEntitiesResult xmlns:a=&#34;namespace_3&#34; xmlns:i=&#34;namespace_4&#34;&gt;
            &lt;a:DefinedEntity&gt;
               &lt;a:Description&gt;Some Description&lt;/a:Description&gt;
               &lt;a:Name&gt;Some entity name&lt;/a:Name&gt;
            &lt;/a:DefinedEntity&gt;
         &lt;/DefinedEntitiesResult&gt;
      &lt;/DefinedEntitiesResponse&gt;
   &lt;/s:Body&gt;
&lt;/s:Envelope&gt;
</code></pre>

<p>我尝试这样解析:</p>

<pre><code>CXMLDocument *doc = [[ initWithXMLString: options:0 error:nil] autorelease];

NSArray *resultNodes = ;
NSLog(@&#34;Resultnodes: %@&#34;, resultNodes);
</code></pre>

<p>得到错误:</p>

<pre><code>XPath error : Undefined namespace prefix
XPath error : Invalid expression
</code></pre>

<p>问题 1:我做错了什么?
问题 2:我应该使用 TouchXML 作为库,还是有更简单更好的方法?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>使用以下 <a href="https://github.com/Insert-Witty-Name" rel="noreferrer noopener nofollow">project on github</a>将您的 XML 解析为 NSDictionary。然后,您可以使用 <code>NSPredicate</code> 在已解析的字典中查找值。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - TouchXML 命名空间解析?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7713104/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7713104/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - TouchXML 命名空间解析?