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, *_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 }
41 
45 @property (nonatomic, copy) OFString *name;
46 
50 #ifndef __cplusplus
51 @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFString *namespace;
52 #else
53 @property OF_NULLABLE_PROPERTY (nonatomic, copy,
54  getter=namespace, setter=setNamespace:) OFString *namespace_;
55 #endif
56 
60 @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFString *defaultNamespace;
61 
68 + (instancetype)elementWithName: (OFString *)name;
69 
78 + (instancetype)elementWithName: (OFString *)name
79  stringValue: (nullable OFString *)stringValue;
80 
89 + (instancetype)elementWithName: (OFString *)name
90  namespace: (nullable OFString *)namespace_;
91 
102 + (instancetype)elementWithName: (OFString *)name
103  namespace: (nullable OFString *)namespace_
104  stringValue: (nullable OFString *)stringValue;
105 
113 + (instancetype)elementWithElement: (OFXMLElement *)element;
114 
121 + (instancetype)elementWithXMLString: (OFString *)string;
122 
123 #ifdef OF_HAVE_FILES
124 
131 + (instancetype)elementWithFile: (OFString *)path;
132 #endif
133 
134 - init OF_UNAVAILABLE;
135 
142 - initWithName: (OFString *)name;
143 
153 - initWithName: (OFString *)name
154  stringValue: (nullable OFString *)stringValue;
155 
165 - initWithName: (OFString *)name
166  namespace: (nullable OFString *)namespace_;
167 
178 - initWithName: (OFString *)name
179  namespace: (nullable OFString *)namespace_
180  stringValue: (nullable OFString *)stringValue;
181 
190 - initWithElement: (OFXMLElement *)element;
191 
199 - initWithXMLString: (OFString *)string;
200 
201 #ifdef OF_HAVE_FILES
202 
209 - initWithFile: (OFString *)path;
210 #endif
211 
212 - initWithSerialization: (OFXMLElement *)element;
213 
220 - (void)setPrefix: (OFString *)prefix
221  forNamespace: (OFString *)namespace_;
222 
229 - (void)bindPrefix: (OFString *)prefix
230  forNamespace: (OFString *)namespace_;
231 
237 - (nullable OFArray OF_GENERIC(OFXMLAttribute *) *)attributes;
238 
247 - (void)addAttribute: (OFXMLAttribute *)attribute;
248 
258 - (void)addAttributeWithName: (OFString *)name
259  stringValue: (OFString *)stringValue;
260 
272 - (void)addAttributeWithName: (OFString *)name
273  namespace: (nullable OFString *)namespace_
274  stringValue: (OFString *)stringValue;
275 
282 - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName;
283 
291 - (nullable OFXMLAttribute *)attributeForName: (OFString *)attributeName
292  namespace: (nullable OFString *)attributeNS;
293 
299 - (void)removeAttributeForName: (OFString *)attributeName;
300 
307 - (void)removeAttributeForName: (OFString *)attributeName
308  namespace: (nullable OFString *)attributeNS;
309 
315 - (void)setChildren: (nullable OFArray OF_GENERIC(OFXMLNode *) *)children;
316 
322 - (nullable OFArray OF_GENERIC(OFXMLNode *) *)children;
323 
329 - (void)addChild: (OFXMLNode *)child;
330 
337 - (void)insertChild: (OFXMLNode *)child
338  atIndex: (size_t)index;
339 
346 - (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode *) *)children
347  atIndex: (size_t)index;
348 
354 - (void)removeChild: (OFXMLNode *)child;
355 
362 - (void)removeChildAtIndex: (size_t)index;
370 - (void)replaceChild: (OFXMLNode *)child
371  withNode: (OFXMLNode *)node;
372 
379 - (void)replaceChildAtIndex: (size_t)index
380  withNode: (OFXMLNode *)node;
381 
387 - (OFArray OF_GENERIC(OFXMLElement *) *)elements;
388 
394 - (OFArray OF_GENERIC(OFXMLElement *) *)elementsForNamespace:
395  (nullable OFString *)elementNS;
396 
403 - (nullable OFXMLElement *)elementForName: (OFString *)elementName;
404 
411 - (OFArray OF_GENERIC(OFXMLElement *) *)elementsForName:
412  (OFString *)elementName;
413 
421 - (nullable OFXMLElement *)elementForName: (OFString *)elementName
422  namespace: (nullable OFString *)elementNS;
423 
431 - (OFArray OF_GENERIC(OFXMLElement *) *)
432  elementsForName: (OFString *)elementName
433  namespace: (nullable OFString *)elementNS;
434 @end
435 
436 OF_ASSUME_NONNULL_END
437 
438 #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:51
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
OFString * name
Definition: OFXMLElement.h:45
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