ObjFW
OFXMLElement.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
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 OFString;
22 @class OFMutableString;
23 #ifndef DOXYGEN
24 @class OFArray OF_GENERIC(ObjectType);
25 @class OFMutableArray OF_GENERIC(ObjectType);
26 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
27 #endif
28 @class OFXMLAttribute;
29 
36 {
37  OFString *_name, *_namespace, *_defaultNamespace;
38  OFMutableArray OF_GENERIC(OFXMLAttribute*) *_attributes;
39  OFMutableDictionary OF_GENERIC(OFString*, OFString*) *_namespaces;
40  OFMutableArray OF_GENERIC(OFXMLNode*) *_children;
41 }
42 
43 #ifdef OF_HAVE_PROPERTIES
44 @property (copy) OFString *name;
45 # ifdef __cplusplus
46 @property OF_NULLABLE_PROPERTY (copy, getter=namespace, setter=setNamespace:)
47  OFString *namespace_;
48 # else
49 @property OF_NULLABLE_PROPERTY (copy) OFString *namespace;
50 # endif
51 @property OF_NULLABLE_PROPERTY (copy) OFString *defaultNamespace;
52 @property OF_NULLABLE_PROPERTY (copy, readonly)
53  OFArray OF_GENERIC(OFXMLAttribute*) *attributes;
54 @property OF_NULLABLE_PROPERTY (copy) OFArray OF_GENERIC(OFXMLNode*) *children;
55 #endif
56 
63 + (instancetype)elementWithName: (OFString*)name;
64 
73 + (instancetype)elementWithName: (OFString*)name
74  stringValue: (nullable OFString*)stringValue;
75 
84 + (instancetype)elementWithName: (OFString*)name
85  namespace: (nullable OFString*)namespace_;
86 
97 + (instancetype)elementWithName: (OFString*)name
98  namespace: (nullable OFString*)namespace_
99  stringValue: (nullable OFString*)stringValue;
100 
108 + (instancetype)elementWithElement: (OFXMLElement*)element;
109 
116 + (instancetype)elementWithXMLString: (OFString*)string;
117 
118 #ifdef OF_HAVE_FILES
119 
126 + (instancetype)elementWithFile: (OFString*)path;
127 #endif
128 
135 - initWithName: (OFString*)name;
136 
146 - initWithName: (OFString*)name
147  stringValue: (nullable OFString*)stringValue;
148 
158 - initWithName: (OFString*)name
159  namespace: (nullable OFString*)namespace_;
160 
171 - initWithName: (OFString*)name
172  namespace: (nullable OFString*)namespace_
173  stringValue: (nullable OFString*)stringValue;
174 
183 - initWithElement: (OFXMLElement*)element;
184 
192 - initWithXMLString: (OFString*)string;
193 
194 #ifdef OF_HAVE_FILES
195 
202 - initWithFile: (OFString*)path;
203 #endif
204 
210 - (void)setName: (OFString*)name;
211 
217 - (OFString*)name;
218 
224 - (void)setNamespace: (nullable OFString*)namespace_;
225 
231 - (nullable OFString*)namespace;
232 
239 - (void)setPrefix: (OFString*)prefix
240  forNamespace: (OFString*)namespace_;
241 
248 - (void)bindPrefix: (OFString*)prefix
249  forNamespace: (OFString*)namespace_;
250 
257 - (void)setDefaultNamespace: (nullable OFString*)defaultNamespace;
258 
266 - (nullable OFString*)defaultNamespace;
267 
273 - (nullable OFArray OF_GENERIC(OFXMLAttribute*)*)attributes;
274 
283 - (void)addAttribute: (OFXMLAttribute*)attribute;
284 
294 - (void)addAttributeWithName: (OFString*)name
295  stringValue: (OFString*)stringValue;
296 
308 - (void)addAttributeWithName: (OFString*)name
309  namespace: (nullable OFString*)namespace_
310  stringValue: (OFString*)stringValue;
311 
318 - (OFXMLAttribute*)attributeForName: (OFString*)attributeName;
319 
327 - (OFXMLAttribute*)attributeForName: (OFString*)attributeName
328  namespace: (nullable OFString*)attributeNS;
329 
335 - (void)removeAttributeForName: (OFString*)attributeName;
336 
343 - (void)removeAttributeForName: (OFString*)attributeName
344  namespace: (nullable OFString*)attributeNS;
345 
351 - (void)setChildren: (nullable OFArray OF_GENERIC(OFXMLNode*)*)children;
352 
358 - (nullable OFArray OF_GENERIC(OFXMLNode*)*)children;
359 
365 - (void)addChild: (OFXMLNode*)child;
366 
373 - (void)insertChild: (OFXMLNode*)child
374  atIndex: (size_t)index;
375 
382 - (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode*)*)children
383  atIndex: (size_t)index;
384 
390 - (void)removeChild: (OFXMLNode*)child;
391 
398 - (void)removeChildAtIndex: (size_t)index;
406 - (void)replaceChild: (OFXMLNode*)child
407  withNode: (OFXMLNode*)node;
408 
415 - (void)replaceChildAtIndex: (size_t)index
416  withNode: (OFXMLNode*)node;
417 
423 - (OFArray OF_GENERIC(OFXMLElement*)*)elements;
424 
430 - (OFArray OF_GENERIC(OFXMLElement*)*)elementsForNamespace:
431  (nullable OFString*)elementNS;
432 
439 - (OFXMLElement*)elementForName: (OFString*)elementName;
440 
447 - (OFArray OF_GENERIC(OFXMLElement*)*)elementsForName: (OFString*)elementName;
448 
456 - (OFXMLElement*)elementForName: (OFString*)elementName
457  namespace: (nullable OFString*)elementNS;
458 
466 - (OFArray OF_GENERIC(OFXMLElement*)*)
467  elementsForName: (OFString*)elementName
468  namespace: (nullable OFString*)elementNS;
469 @end
470 
471 OF_ASSUME_NONNULL_END
472 
473 #import "OFXMLElement+Serialization.h"
An abstract class for storing objects in an array.
Definition: OFArray.h:95
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:35
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:46
A class for handling strings.
Definition: OFString.h:91
A class which stores an XML element.
Definition: OFXMLNode.h:27
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:47
A class for storing and modifying strings.
Definition: OFMutableString.h:26