Retrieving the Inner XML for a node

70 views
Skip to first unread message

Brian Rice

unread,
Jan 16, 2010, 6:26:12 AM1/16/10
to KissXML
Is there any way to retrieve the "inner" xml for a node? Essentially
node.stringValue, but without stripping out the tags.

For example:
<rss>
<channel>
<pubDate>Fri, 15 Jan 2010 16:31:02 PST</pubDate>
<textInput>
<title>Search News@Cisco</title>
<description></description>
<name>searchPhrase</name>
<link>http://www.cisco.com/pcgi-bin/search/search.pl</link>
</textInput>
</channel>
</rss>

So, for the pubDate node it would return: "Fri, 15 Jan 2010 16:31:02
PST"
But, for the textInput node it would return: "<title>News@Cisco</
title><description></description> ... </link>"

Thanks!

- Brian

Robbie Hanson

unread,
Jan 19, 2010, 9:05:41 AM1/19/10
to kis...@googlegroups.com
I believe you may be looking for the stringValue method. Let me know
if this is incorrect.

-Robbie Hanson
Sent from my iPhone

> --
> You received this message because you are subscribed to the Google
> Groups "KissXML" group.
> To post to this group, send email to kis...@googlegroups.com.
> To unsubscribe from this group, send email to kissxml+u...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/kissxml?hl=en
> .
>
>

Brian Rice

unread,
Jan 19, 2010, 11:16:05 PM1/19/10
to KissXML
My testing seemed to indicate that xml tags are stripped out by
stringValue.

So, if you take my example, textInput node would return:
"News@CiscosearchPhrasehttp:// ..." rather than "<title>News@Cisco</


title><description></description> ... </link>"

- Brian

On Jan 19, 8:05 am, Robbie Hanson <robbiehan...@deusty.com> wrote:
> I believe you may be looking for the stringValue method. Let me know  
> if this is incorrect.
>
> -Robbie Hanson
> Sent from my iPhone
>

Robbie Hanson

unread,
Jan 20, 2010, 3:08:52 AM1/20/10
to kis...@googlegroups.com
Oops, you're right.  You could invoke the XMLString method on each of the children, and concatenate the results.  Something like this (a category method on DDXMLNode):

- (NSString *)innerXMLString
{
NSMutableString *mStr = [[NSMutableString alloc] init];


NSEnumerator *enumerator = [[self children] objectEnumerator];
NSXMLNode *child;


while(child = [enumerator nextObject])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];


NSString *str = [child XMLString];
if(str)
{
// From the documentation:
// The string to append must not be nil.


[mStr appendString:str];
}


[pool release];
}


return [mStr autorelease];
}

-Robbie Hanson
-Deusty Designs



Brian Rice

unread,
Jan 20, 2010, 10:22:02 AM1/20/10
to KissXML
It's really too bad there is no function for this... it seems like I
would have to extract stuff from a lot of different areas. For
example... the node name, node attributes, comments, text nodes,
cdata... all kinds of things... that unfortunately I am sure I am
either unaware of or likely to forget something when I'm trying to
exactly recreate the inner xml of a node.

Any help would be appreciated! :)

Thanks.

- Brian

Robbie Hanson

unread,
Jan 21, 2010, 7:24:37 PM1/21/10
to kis...@googlegroups.com
The code that I posted passes your original 2 tests. I think it's
exactly what you want. I tested it before I posted it.

-Robbie Hanson
Sent from my iPhone

Reply all
Reply to author
Forward
0 new messages