Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -204,19 +204,35 @@ * \param ns The namespace for which the prefix is set */ - (void)setPrefix: (OFString*)prefix forNamespace: (OFString*)ns; +/** + * Binds a prefix for a namespace. + * + * \param prefix The prefix for the namespace + * \param ns The namespace for which the prefix is bound + */ +- (void)bindPrefix: (OFString*)prefix + forNamespace: (OFString*)ns; + /** * Sets the default namespace for the element. * * \param ns The default namespace for the element */ - (void)setDefaultNamespace: (OFString*)ns; +/** + * Binds the default namespace for the element. + * + * \param ns The default namespace for the element + */ +- (void)bindDefaultNamespace: (OFString*)ns; + /** * Adds a child to the OFXMLElement. * * \param child Another OFXMLElement which is added as a child */ - (void)addChild: (OFXMLElement*)child; @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -409,10 +409,20 @@ ns = @""; [namespaces setObject: prefix forKey: ns]; } + +- (void)bindPrefix: (OFString*)prefix + forNamespace: (OFString*)ns +{ + [self setPrefix: prefix + forNamespace: ns]; + [self addAttributeWithName: prefix + namespace: @"http://www.w3.org/2000/xmlns/" + stringValue: ns]; +} - (OFString*)defaultNamespace { if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa @@ -429,10 +439,17 @@ OFString *old = defaultNamespace; defaultNamespace = [ns copy]; [old release]; } + +- (void)bindDefaultNamespace: (OFString*)ns +{ + [self setDefaultNamespace: ns]; + [self addAttributeWithName: @"xmlns" + stringValue: ns]; +} - (void)addChild: (OFXMLElement*)child { if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa