Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -34,11 +34,11 @@ OFMutableArray *attributes; OFMutableDictionary *namespaces; OFMutableArray *children; OFString *characters; OFString *CDATA; - OFMutableString *comment; + OFString *comment; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy) OFString *name; @property (readonly, copy, getter=namespace) OFString *ns; @@ -105,10 +105,17 @@ * \param comment The comment the element represents * \return A new autoreleased OFXMLElement consisting of the specified comment */ + elementWithComment: (OFString*)comment; +/** + * \param element An OFXMLElement to initialize the OFXMLElement with + * \return A new autoreleased OFXMLElement with the contents of the specified + * element + */ ++ elementWithElement: (OFXMLElement*)element; + /** * Parses the string and returns an OFXMLElement for it. * * \param string The string to parse * \return A new autoreleased OFXMLElement with the contents of the string @@ -187,10 +194,20 @@ * \param comment The comment the element represents * \return An initialized OFXMLElement consisting of the specified comment */ - initWithComment: (OFString*)comment; +/** + * Initializes an already allocated OFXMLElement with the specified + * OFXMLElement. + * + * \param element An OFXMLElement to initialize the OFXMLElement with + * \return A new autoreleased OFXMLElement with the contents of the specified + * element + */ +- initWithElement: (OFXMLElement*)element; + /** * Parses the string and initializes an already allocated OFXMLElement with it. * * \param string The string to parse * \return An initialized OFXMLElement with the contents of the string Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -96,10 +96,15 @@ + elementWithComment: (OFString*)comment { return [[[self alloc] initWithComment: comment] autorelease]; } + ++ elementWithElement: (OFXMLElement*)element +{ + return [[[self alloc] initWithElement: element] autorelease]; +} + elementWithXMLString: (OFString*)string { return [[[self alloc] initWithXMLString: string] autorelease]; } @@ -202,10 +207,32 @@ comment = [comment_ copy]; } @catch (id e) { [self release]; @throw e; } + + return self; +} + +- initWithElement: (OFXMLElement*)element +{ + self = [super init]; + + @try { + name = [element->name copy]; + ns = [element->ns copy]; + defaultNamespace = [element->defaultNamespace copy]; + attributes = [element->attributes mutableCopy]; + namespaces = [element->namespaces mutableCopy]; + children = [element->children mutableCopy]; + characters = [element->characters copy]; + CDATA = [element->CDATA copy]; + comment = [element->comment copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithXMLString: (OFString*)string