0

I am trying to parse HTML using an Xpath query string (in Objective-C for iOS). I'm grabbing the element I want, but with everything except the contents.

Example html:

<textarea type="text" name="name" style="width: 100px; height:100px;"/>Contents</textarea>

My attempt to grab the element:

TFHpple *parser = [TFHpple hppleWithHTMLData:response];
NSString *XpathQueryString = @"//textarea[@name='name']";
NSArray *nodes = [parser searchWithXPathQuery:XpathQueryString];

NSLog of the element in the nodes array:

nodeAttributeArray =     (
            {
        attributeName = type;
        nodeContent = text;
    },
            {
        attributeName = name;
        nodeContent = name;
    },
            {
        attributeName = style;
        nodeContent = "width: 100px; height:100px;";
    }
);
nodeName = textarea;
raw = "<textarea type=\"text\" name=\"name\" style=\"width: 100px; height:100px;\"></textarea>";
}

No contents. Any ideas as to what is going wrong?

Thanks in advance!

Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
Benny B
  • 357
  • 1
  • 3
  • 13
  • Well `` is an empty element as the trailing `/>` closes the tag, at least in X(HT)ML syntax. On the other hand, pure XML parsing would then give an error on the `` that follows. – Martin Honnen Jun 30 '14 at 07:49
  • Okay I see that now. So is this a problem with what I am trying to parse or how am I trying to parse it? – Benny B Jun 30 '14 at 13:50

1 Answers1

0

Looks like this is a case of bad html. The tag self closes but also has a separate closing tag.

Should like like this:

<textarea type="text" name="name" style="width: 100px; height:100px;">Contents</textarea>
Benny B
  • 357
  • 1
  • 3
  • 13