ObjFW
OFXMLElement.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFXMLNode.h"
17 
18 OF_ASSUME_NONNULL_BEGIN
19 
20 @class OFArray OF_GENERIC(ObjectType);
21 @class OFMutableArray OF_GENERIC(ObjectType);
22 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
23 @class OFMutableString;
24 @class OFStream;
25 @class OFString;
26 @class OFXMLAttribute;
27 
34 {
35  OFString *_name, *_Nullable _namespace, *_Nullable _defaultNamespace;
36  OFMutableArray OF_GENERIC(OFXMLAttribute *) *_Nullable _attributes;
37  OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_Nullable
38  _namespaces;
39  OFMutableArray OF_GENERIC(OFXMLNode *) *_Nullable _children;
40  OF_RESERVE_IVARS(OFXMLElement, 4)
41 }
42 
46 @property (copy, nonatomic) OFString *name;
47 
51 #ifndef __cplusplus
52 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *namespace;
53 #else
54 @property OF_NULLABLE_PROPERTY (copy, nonatomic,
55  getter=namespace, setter=setNamespace:) OFString *namespace_;
56 #endif
57 
62 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *defaultNamespace;
63 
67 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
68  OFArray OF_GENERIC(OFXMLAttribute *) *attributes;
69 
73 @property OF_NULLABLE_PROPERTY (nonatomic, copy)
74  OFArray OF_GENERIC(OFXMLNode *) *children;
75 
79 @property (readonly, nonatomic) OFArray OF_GENERIC(OFXMLElement *) *elements;
80 
87 + (instancetype)elementWithName: (OFString *)name;
88 
97 + (instancetype)elementWithName: (OFString *)name
98  stringValue: (nullable OFString *)stringValue;
99 
108 + (instancetype)elementWithName: (OFString *)name
109  namespace: (nullable OFString *)namespace_;
110 
121 + (instancetype)elementWithName: (OFString *)name
122  namespace: (nullable OFString *)namespace_
123  stringValue: (nullable OFString *)stringValue;
124 
132 + (instancetype)elementWithElement: (OFXMLElement *)element;
133 
140 + (instancetype)elementWithXMLString: (OFString *)string;
141 
149 + (instancetype)elementWithStream: (OFStream *)stream;
150 
151 - (instancetype)init OF_UNAVAILABLE;
152 
159 - (instancetype)initWithName: (OFString *)name;
160 
170 - (instancetype)initWithName: (OFString *)name
171  stringValue: (nullable OFString *)stringValue;
172 
182 - (instancetype)initWithName: (OFString *)name
183  namespace: (nullable OFString *)namespace_;
184 
195 - (instancetype)initWithName: (OFString *)name
196  namespace: (nullable OFString *)namespace_
197  stringValue: (nullable OFString *)stringValue;
198 
207 - (instancetype)initWithElement: (OFXMLElement *)element;
208 
216 - (instancetype)initWithXMLString: (OFString *)string;
217 
225 - (instancetype)initWithStream: (OFStream *)stream;
226 
227 - (instancetype)initWithSerialization: (OFXMLElement *)element;
228 
235 - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace_;
236 
243 - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace_;
244 
253 - (void)addAttribute: (OFXMLAttribute *)attribute;
254 
264 - (void)addAttributeWithName: (OFString *)name
265  stringValue: (OFString *)stringValue;
266 
278 - (void)addAttributeWithName: (OFString *)name
279  namespace: (nullable OFString *)namespace_
280  stringValue: (OFString *)stringValue;
281 
288 - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName;
289 
297 - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName
298  namespace: (nullable OFString *)attributeNS;
299 
305 - (void)removeAttributeForName: (OFString *)attributeName;
306 
313 - (void)removeAttributeForName: (OFString *)attributeName
314  namespace: (nullable OFString *)attributeNS;
315 
321 - (void)addChild: (OFXMLNode *)child;
322 
329 - (void)insertChild: (OFXMLNode *)child atIndex: (size_t)index;
330 
337 - (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode *) *)children
338  atIndex: (size_t)index;
339 
345 - (void)removeChild: (OFXMLNode *)child;
346 
353 - (void)removeChildAtIndex: (size_t)index;
361 - (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node;
362 
369 - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode *)node;
370 
376 - (OFArray OF_GENERIC(OFXMLElement *) *)elementsForNamespace:
377  (nullable OFString *)elementNS;
378 
385 - (nullable OFXMLElement *)elementForName: (OFString *)elementName;
386 
393 - (OFArray OF_GENERIC(OFXMLElement *) *)elementsForName:
394  (OFString *)elementName;
395 
403 - (nullable OFXMLElement *)elementForName: (OFString *)elementName
404  namespace: (nullable OFString *)elementNS;
405 
413 - (OFArray OF_GENERIC(OFXMLElement *) *)
414  elementsForName: (OFString *)elementName
415  namespace: (nullable OFString *)elementNS;
416 @end
417 
418 OF_ASSUME_NONNULL_END
419 
420 #import "OFXMLElement+Serialization.h"
An abstract class for storing objects in an array.
Definition: OFArray.h:92
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:44
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:44
A class for storing and modifying strings.
Definition: OFMutableString.h:30
A base class for different types of streams.
Definition: OFStream.h:191
A class for handling strings.
Definition: OFString.h:132
A representation of an attribute of an XML element as an object.
Definition: OFXMLAttribute.h:28
A class which stores an XML element.
Definition: OFXMLElement.h:34
OFString * defaultNamespace
The namespace of the element.
Definition: OFXMLElement.h:52
A class which stores an XML element.
Definition: OFXMLNode.h:30