ObjFW
OFXMLElement.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFXMLNode.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
21 @class OFArray OF_GENERIC(ObjectType);
22 @class OFMutableArray OF_GENERIC(ObjectType);
23 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
24 @class OFMutableString;
25 @class OFString;
26 @class OFXMLAttribute;
27 
34 {
35  OFString *_name, *_namespace, *_defaultNamespace;
36  OFMutableArray OF_GENERIC(OFXMLAttribute *) *_attributes;
37  OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_namespaces;
38  OFMutableArray OF_GENERIC(OFXMLNode *) *_children;
39 }
40 
44 @property (nonatomic, copy) OFString *name;
45 
49 #ifndef __cplusplus
50 @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFString *namespace;
51 #else
52 @property OF_NULLABLE_PROPERTY (nonatomic, copy,
53  getter=namespace, setter=setNamespace:) OFString *namespace_;
54 #endif
55 
59 @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFString *defaultNamespace;
60 
67 + (instancetype)elementWithName: (OFString *)name;
68 
77 + (instancetype)elementWithName: (OFString *)name
78  stringValue: (nullable OFString *)stringValue;
79 
88 + (instancetype)elementWithName: (OFString *)name
89  namespace: (nullable OFString *)namespace_;
90 
101 + (instancetype)elementWithName: (OFString *)name
102  namespace: (nullable OFString *)namespace_
103  stringValue: (nullable OFString *)stringValue;
104 
112 + (instancetype)elementWithElement: (OFXMLElement *)element;
113 
120 + (instancetype)elementWithXMLString: (OFString *)string;
121 
122 #ifdef OF_HAVE_FILES
123 
130 + (instancetype)elementWithFile: (OFString *)path;
131 #endif
132 
133 - init OF_UNAVAILABLE;
134 
141 - initWithName: (OFString *)name;
142 
152 - initWithName: (OFString *)name
153  stringValue: (nullable OFString *)stringValue;
154 
164 - initWithName: (OFString *)name
165  namespace: (nullable OFString *)namespace_;
166 
177 - initWithName: (OFString *)name
178  namespace: (nullable OFString *)namespace_
179  stringValue: (nullable OFString *)stringValue;
180 
189 - initWithElement: (OFXMLElement *)element;
190 
198 - initWithXMLString: (OFString *)string;
199 
200 #ifdef OF_HAVE_FILES
201 
208 - initWithFile: (OFString *)path;
209 #endif
210 
211 - initWithSerialization: (OFXMLElement *)element;
212 
219 - (void)setPrefix: (OFString *)prefix
220  forNamespace: (OFString *)namespace_;
221 
228 - (void)bindPrefix: (OFString *)prefix
229  forNamespace: (OFString *)namespace_;
230 
236 - (nullable OFArray OF_GENERIC(OFXMLAttribute *) *)attributes;
237 
246 - (void)addAttribute: (OFXMLAttribute *)attribute;
247 
257 - (void)addAttributeWithName: (OFString *)name
258  stringValue: (OFString *)stringValue;
259 
271 - (void)addAttributeWithName: (OFString *)name
272  namespace: (nullable OFString *)namespace_
273  stringValue: (OFString *)stringValue;
274 
281 - (OFXMLAttribute *)attributeForName: (OFString *)attributeName;
282 
290 - (OFXMLAttribute *)attributeForName: (OFString *)attributeName
291  namespace: (nullable OFString *)attributeNS;
292 
298 - (void)removeAttributeForName: (OFString *)attributeName;
299 
306 - (void)removeAttributeForName: (OFString *)attributeName
307  namespace: (nullable OFString *)attributeNS;
308 
314 - (void)setChildren: (nullable OFArray OF_GENERIC(OFXMLNode *) *)children;
315 
321 - (nullable OFArray OF_GENERIC(OFXMLNode *) *)children;
322 
328 - (void)addChild: (OFXMLNode *)child;
329 
336 - (void)insertChild: (OFXMLNode *)child
337  atIndex: (size_t)index;
338 
345 - (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode *) *)children
346  atIndex: (size_t)index;
347 
353 - (void)removeChild: (OFXMLNode *)child;
354 
361 - (void)removeChildAtIndex: (size_t)index;
369 - (void)replaceChild: (OFXMLNode *)child
370  withNode: (OFXMLNode *)node;
371 
378 - (void)replaceChildAtIndex: (size_t)index
379  withNode: (OFXMLNode *)node;
380 
386 - (OFArray OF_GENERIC(OFXMLElement *) *)elements;
387 
393 - (OFArray OF_GENERIC(OFXMLElement *) *)elementsForNamespace:
394  (nullable OFString *)elementNS;
395 
402 - (OFXMLElement *)elementForName: (OFString *)elementName;
403 
410 - (OFArray OF_GENERIC(OFXMLElement *) *)elementsForName:
411  (OFString *)elementName;
412 
420 - (OFXMLElement *)elementForName: (OFString *)elementName
421  namespace: (nullable OFString *)elementNS;
422 
430 - (OFArray OF_GENERIC(OFXMLElement *) *)
431  elementsForName: (OFString *)elementName
432  namespace: (nullable OFString *)elementNS;
433 @end
434 
435 OF_ASSUME_NONNULL_END
436 
437 #import "OFXMLElement+Serialization.h"
A class which stores an XML element.
Definition: OFXMLNode.h:29
id copy()
Returns the class.
Definition: OFObject.m:1133
A class for storing and modifying strings.
Definition: OFMutableString.h:26
A class for handling strings.
Definition: OFString.h:114
nonatomic
Definition: OFXMLElement.h:50
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
OFString * name
Definition: OFXMLElement.h:44
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:39
nullable OFArray * attributes()
Returns an OFArray with the attributes of the element.
Definition: OFXMLElement.m:376
A class which stores an XML element.
Definition: OFXMLElement.h:33
An abstract class for storing objects in an array.
Definition: OFArray.h:89
A representation of an attribute of an XML element as an object.
Definition: OFXMLAttribute.h:28
OFArray * elements()
Returns all children that are elements.
Definition: OFXMLElement.m:956
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:40