ObjFW
OFXMLElement.h
1 /*
2  * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFXMLNode.h"
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
24 @class OFArray OF_GENERIC(ObjectType);
25 @class OFMutableArray OF_GENERIC(ObjectType);
26 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
27 @class OFMutableString;
28 @class OFStream;
29 @class OFString;
30 @class OFXMLAttribute;
31 
38 {
39  OFString *_name, *_Nullable _namespace;
40  OFMutableArray OF_GENERIC(OFXMLAttribute *) *_Nullable _attributes;
41  OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_Nullable
42  _namespaces;
43  OFMutableArray OF_GENERIC(OFXMLNode *) *_Nullable _children;
44  OF_RESERVE_IVARS(OFXMLElement, 4)
45 }
46 
50 @property (copy, nonatomic) OFString *name;
51 
55 #ifndef __cplusplus
56 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *namespace;
57 #else
58 @property OF_NULLABLE_PROPERTY (copy, nonatomic,
59  getter=namespace, setter=setNamespace:) OFString *nameSpace;
60 #endif
61 
65 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
66  OFArray OF_GENERIC(OFXMLAttribute *) *attributes;
67 
71 @property OF_NULLABLE_PROPERTY (nonatomic, copy)
72  OFArray OF_GENERIC(OFXMLNode *) *children;
73 
77 @property (readonly, nonatomic) OFArray OF_GENERIC(OFXMLElement *) *elements;
78 
85 + (instancetype)elementWithName: (OFString *)name;
86 
95 + (instancetype)elementWithName: (OFString *)name
96  stringValue: (nullable OFString *)stringValue;
97 
106 + (instancetype)elementWithName: (OFString *)name
107  namespace: (nullable OFString *)nameSpace;
108 
119 + (instancetype)elementWithName: (OFString *)name
120  namespace: (nullable OFString *)nameSpace
121  stringValue: (nullable OFString *)stringValue;
122 
129 + (instancetype)elementWithElement: (OFXMLElement *)element;
130 
141 + (instancetype)elementWithXMLString: (OFString *)string;
142 
154 + (instancetype)elementWithStream: (OFStream *)stream;
155 
156 - (instancetype)init OF_UNAVAILABLE;
157 
164 - (instancetype)initWithName: (OFString *)name;
165 
175 - (instancetype)initWithName: (OFString *)name
176  stringValue: (nullable OFString *)stringValue;
177 
187 - (instancetype)initWithName: (OFString *)name
188  namespace: (nullable OFString *)nameSpace
189  OF_DESIGNATED_INITIALIZER;
190 
201 - (instancetype)initWithName: (OFString *)name
202  namespace: (nullable OFString *)nameSpace
203  stringValue: (nullable OFString *)stringValue;
204 
212 - (instancetype)initWithElement: (OFXMLElement *)element;
213 
225 - (instancetype)initWithXMLString: (OFString *)string;
226 
238 - (instancetype)initWithStream: (OFStream *)stream;
239 
246 - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)nameSpace;
247 
254 - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)nameSpace;
255 
264 - (void)addAttribute: (OFXMLAttribute *)attribute;
265 
275 - (void)addAttributeWithName: (OFString *)name
276  stringValue: (OFString *)stringValue;
277 
289 - (void)addAttributeWithName: (OFString *)name
290  namespace: (nullable OFString *)nameSpace
291  stringValue: (OFString *)stringValue;
292 
299 - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName;
300 
308 - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName
309  namespace: (nullable OFString *)attributeNS;
310 
316 - (void)removeAttributeForName: (OFString *)attributeName;
317 
324 - (void)removeAttributeForName: (OFString *)attributeName
325  namespace: (nullable OFString *)attributeNS;
326 
332 - (void)addChild: (OFXMLNode *)child;
333 
340 - (void)insertChild: (OFXMLNode *)child atIndex: (size_t)index;
341 
348 - (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode *) *)children
349  atIndex: (size_t)index;
350 
356 - (void)removeChild: (OFXMLNode *)child;
357 
363 - (void)removeChildAtIndex: (size_t)index;
364 
372 - (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node;
373 
380 - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode *)node;
381 
387 - (OFArray OF_GENERIC(OFXMLElement *) *)
388  elementsForNamespace: (nullable OFString *)elementNS;
389 
396 - (nullable OFXMLElement *)elementForName: (OFString *)elementName;
397 
404 - (OFArray OF_GENERIC(OFXMLElement *) *)
405  elementsForName: (OFString *)elementName;
406 
414 - (nullable OFXMLElement *)elementForName: (OFString *)elementName
415  namespace: (nullable OFString *)elementNS;
416 
424 - (OFArray OF_GENERIC(OFXMLElement *) *)
425  elementsForName: (OFString *)elementName
426  namespace: (nullable OFString *)elementNS;
427 
439 - (OFString *)XMLStringWithIndentation: (unsigned int)indentation;
440 
453 - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS
454  indentation: (unsigned int)indentation;
455 @end
456 
457 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:108
A representation of an attribute of an XML element as an object.
Definition: OFXMLAttribute.h:32
A class which stores an XML element.
Definition: OFXMLElement.h:37
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:49
A base class for different types of streams.
Definition: OFStream.h:278
A class for handling strings.
Definition: OFString.h:142
A class which stores an XML element.
Definition: OFXMLNode.h:29
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:46
A class for storing and modifying strings.
Definition: OFMutableString.h:29