ios - Get text value only from NSXMLElement without the text of child nodes -
i use kissxml, drop replacement nsxmldocument, etc. contents of nsxmlelement:
<ar> <k>baker</k> <tr>ˈbeɪkə</tr> baker пекарь, булочник </ar> i want text value of nsxmlelement node without text of child nodes. so, should return only:
baker пекарь, булочник this not working:
_articletext = [xmlelement stringvalue]; it returns everything, including text of tr , k child nodes.
p.s. got ar node using xpath , i'm searching xpath solution preferably, not want remove substrings.
nsarray *array = [self.xmldocument nodesforxpath:@"/xdxf/ar" error:&error];
assuming 'array' contains 1 element, 's' contain string of interest:
nsarray *array = [self.xmldocument nodesforxpath:@"/xdxf/ar" error:&error]; if([array count] > 0) { nsarray *childrenofar = [array[0] children]; for(nsxmlnode *n in childrenofar) { if([n kind] == nsxmltextkind) { nsstring *s = [n stringvalue]; } } } a faster way text() in xpath query:
nsarray *array = [self.xmldocument nodesforxpath:@"/xdxf/ar/text()" error:&error]; if([array count] > 0) { nsstring *s = [array[0] stringvalue]; }
Comments
Post a Comment