ObjFW
OFXMLElement.h
1 /*
2  * Copyright (c) 2008-2024 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 
133 + (instancetype)elementWithXMLString: (OFString *)string;
134 
146 + (instancetype)elementWithStream: (OFStream *)stream;
147 
148 - (instancetype)init OF_UNAVAILABLE;
149 
156 - (instancetype)initWithName: (OFString *)name;
157 
167 - (instancetype)initWithName: (OFString *)name
168  stringValue: (nullable OFString *)stringValue;
169 
179 - (instancetype)initWithName: (OFString *)name
180  namespace: (nullable OFString *)nameSpace
181  OF_DESIGNATED_INITIALIZER;
182 
193 - (instancetype)initWithName: (OFString *)name
194  namespace: (nullable OFString *)nameSpace
195  stringValue: (nullable OFString *)stringValue;
196 
208 - (instancetype)initWithXMLString: (OFString *)string;
209 
221 - (instancetype)initWithStream: (OFStream *)stream;
222 
229 - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)nameSpace;
230 
237 - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)nameSpace;
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)addChild: (OFXMLNode *)child;
316 
323 - (void)insertChild: (OFXMLNode *)child atIndex: (size_t)index;
324 
331 - (void)insertChildren: (OFArray OF_GENERIC(OFXMLNode *) *)children
332  atIndex: (size_t)index;
333 
339 - (void)removeChild: (OFXMLNode *)child;
340 
346 - (void)removeChildAtIndex: (size_t)index;
347 
355 - (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node;
356 
363 - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode *)node;
364 
370 - (OFArray OF_GENERIC(OFXMLElement *) *)
371  elementsForNamespace: (nullable OFString *)elementNS;
372 
379 - (nullable OFXMLElement *)elementForName: (OFString *)elementName;
380 
387 - (OFArray OF_GENERIC(OFXMLElement *) *)
388  elementsForName: (OFString *)elementName;
389 
397 - (nullable OFXMLElement *)elementForName: (OFString *)elementName
398  namespace: (nullable OFString *)elementNS;
399 
407 - (OFArray OF_GENERIC(OFXMLElement *) *)
408  elementsForName: (OFString *)elementName
409  namespace: (nullable OFString *)elementNS;
410 
422 - (OFString *)XMLStringWithIndentation: (unsigned int)indentation;
423 
436 - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS
437  indentation: (unsigned int)indentation;
438 @end
439 
440 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:107
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:47
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