diff --git a/ChangeLog b/ChangeLog index db72c6fc1..d9dd6eb66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-06-18 Richard Frith-Macdonald + + * Source/Additions/GSXML.m: Implement -description for nodes. + 2003-06-17 Adam Fedor * GNUmakefile (SUBPROJECTS): Add Documentation diff --git a/Headers/gnustep/base/GSXML.h b/Headers/gnustep/base/GSXML.h index f202e59d4..9b42ce2f1 100644 --- a/Headers/gnustep/base/GSXML.h +++ b/Headers/gnustep/base/GSXML.h @@ -113,6 +113,7 @@ - (NSDictionary*) attributes; - (NSString*) content; +- (NSString*) description; - (GSXMLDocument*) document; - (NSString*) escapedContent; - (GSXMLAttribute*) firstAttribute; diff --git a/Source/Additions/GSXML.m b/Source/Additions/GSXML.m index eab50fe3e..175daaacc 100644 --- a/Source/Additions/GSXML.m +++ b/Source/Additions/GSXML.m @@ -340,7 +340,7 @@ static NSMapTable *attrNames = 0; xmlChar *buf = NULL; int length; - xmlDocDumpMemory(lib, &buf, &length); + xmlDocDumpFormatMemoryEnc(lib, &buf, &length, "utf-8", 1); if (buf != 0 && length > 0) { @@ -885,6 +885,31 @@ static NSMapTable *nodeNames = 0; [super dealloc]; } +/** + * Returns a string representation of the node and all its children + * (ie the XML text) or nil if the node does not have reasonable contents. + */ +- (NSString*) description +{ + NSString *string = nil; + xmlOutputBufferPtr buf; + + buf = xmlAllocOutputBuffer(0); + if (buf != 0) + { + xmlNodeDumpOutput(buf, + ((xmlNodePtr)(lib))->doc, + (xmlNodePtr)(lib), + 1, + 1, + "utf-8"); + xmlOutputBufferFlush(buf); + string = UTF8StrLen(buf->buffer->content, buf->buffer->use); + xmlOutputBufferClose(buf); + } + return string; +} + /** * Return the document in which this node exists. */