Is this XPath XHTML parsing request incorrect? using TouchXML

I am trying to parse the XHTMLdoc through TouchXML, but it always cannot find any tags through XPath query.

The following is XHTML:

XHTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta name="generator" content=
         "HTML Tidy for Mac OS X (vers 25 March 2009), see www.w3.org" />
      <title></title>
      </head>
   <body>
      <p>
          <a href="http://www.flickr.com/photos/55397648@N00/5987335786/"
             title="casavermeer5.jpg by the style files, on Flickr">
          <img src="http://farm7.static.flickr.com/6127/5987335786_abec990554_o.jpg"
               width="500" height="750" border="0" alt="casavermeer5.jpg" />
          </a>
      </p>
   </body>
</html>

So we see that there is a p tag, an a tag, and an img tag

What I did then is shown as code below:

CXHTMLDocument *doc = [[[CXHTMLDocument alloc] initWithXHTMLString:XHTML options:0 error:&error] autorelease];
NSLog(@"error %@", [error localizedDescription]);
NSLog(@"doc children count = %d", [doc childCount]);
NSArray *imgNodeArray = [doc nodesForXPath:@"//img" error:&error];
NSLog(@"imgNodeArray = %d", [imgNodeArray count]);
NSLog(@"error %@", [error localizedDescription]);

results

error (null)
doc children count = 2
imgNodeArray = 0
error (null)

Thus, when analyzing a XHTMLdoc document , there are no errors for XPath query. This document also has two children under the root (body tag and "head" tag). But the problem is that he cannot find the "img" tag. I tried replacing "img" with other possible tag names (like p, a, even body, head), no luck.

Can anyone help me here?

PS

- HTML, CTidy TouchXML, HTML XHTML. XHTML CTidy.

XPath,

NSMutableDictionary *namespaceDict = [NSMutableDictionary dictionary];
[namespaceDict setValue:@"http://www.w3.org/1999/xhtml" forKey:@"xhtml"];

XPath

NSArray *imgNodeArray = [doc nodesForXPath:@"//xhtml:img" namespaceMappings:namespaceDict error:&error];

- , .

+5
2

//img. //, img, , .
, //xhtml:img - , .

0

, . , XPaths. UIWebView JavaScript , . , DOM , XPaths . , .

<table>
    <tr>
        <td>Cell</td>
    </tr>
</table>

HTML . ( , .)

<table>
    <thead></thead>
    <tbody>
        <tr>
            <td>Cell</td>
        </tr>
    </tbody>
</table>

, , , HTML.

0

All Articles