Implement description for GSXMLNode

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16954 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-06-18 10:08:02 +00:00
parent 312f539918
commit bdc39efa59
3 changed files with 31 additions and 1 deletions

View file

@ -1,3 +1,7 @@
2003-06-18 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSXML.m: Implement -description for nodes.
2003-06-17 Adam Fedor <fedor@gnu.org>
* GNUmakefile (SUBPROJECTS): Add Documentation

View file

@ -113,6 +113,7 @@
- (NSDictionary*) attributes;
- (NSString*) content;
- (NSString*) description;
- (GSXMLDocument*) document;
- (NSString*) escapedContent;
- (GSXMLAttribute*) firstAttribute;

View file

@ -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.
*/