CommuniGate Pro
Version 1.0
 

XML Object Interface

Some platforms (such as Objective C on Apple iOS) do not provide decent XML libraries. The XIMSS Client library for these platforms is shipped together with a built-in XML library. This section describers this XML library, the XML object and its methods.



Objective C Library

The Objective C version of the XML library is implemented as an STXML class and its methods. This class interface is defined in the STXML.h header file.
//
// XML object Class

//
@interface STXML : NSObject {
....
}

Object Initialization

-(STXML*)initWithTag:(NSString*)theTag prefix:(NSString*)thePrefix namespace:(NSString*)theNamespace;
-(STXML*)initWithName:(NSString*)theTag;

The initWithTag:prefix:namespace: method allows you to initialize an XML object with the specified XML tag and namespace. The namespace and tag are assigned the specified prefix.
If the prefix is nil, an empty string prefix is used.
If the namespace is nil, no namespace is set.

The initWithName: method calls the initWithTag:prefix:namespace: method with the prefix and namespaces parameters set to nil.

Tag Operations

-(NSString*)getTag;
-(NSString*)getTagPrefix;
-(BOOL)isOfTag:(NSString*)theTag namespace:(NSString*)theNamespace;

-(void)setTag:(NSString*)theTag prefix:(NSString*)thePrefix;
-(void)setPrefixedTag:(NSData*)prefixedTag;
The getTag method retrieves the XML object Tag.
The getTagPrefix method retrieves the XML object Tag prefix.
The isOfTag:namespace: method checks if the XML object has the specified Tag in the specified namespace. If the namespace parameter is set to nil, then the function compares only the Tag value and ignores the Tag namespace.

The setTag:prefix: method allows you to change the XML object Tag and its prefix.
The setPrefixedTag: method allows you to change the XML object Tag and its prefix: if the parameter contains the colon (:) symbol, it is interpreted as prefix:tag, otherwise the whole parameter is set as the XML object Tag, and the prefix is set to an empty string.

Namespace Operations

-(NSString*)prefixForNamespace:(NSString*)namespaceName;
-(NSString*)namespaceForPrefix:(NSString*)thePrefix;

-(void)setNamespace:(NSString*)namespaceName forPrefix:(NSString*)thePrefix;

The prefixForNamespace: method retrieves the prefix associated with the specified namespace. The method returns nil if no prefix is associated with the namespace.
The namespaceForPrefix: method retrieves the namespace associated with the specified prefix. The method returns nil if no namespace is associated with the prefix.

The setNamespace:forPrefix: method associates the adds the specified namespace to the XML object and associates the specified prefix with that namespace.

Attribute Operations

-(NSString*)getAttribute:(NSString*)theName prefix:(NSString*)thePrefix;

-(void)setAttribute:(NSString*)theName prefix:(NSString*)thePrefix value:(NSString*)theValue;

The getAttribute: method retrieves attribute with the specified name and prefix. If the prefix name parameter is nil, an empty string is used instead.

The setAttribute:prefix:value: method allows you to add or replace an XML object attribute. If the specified value is nil, the XML object attribute is removed.

Body Operations

-(NSString*)getTextBody;
-(unsigned)childCount;
-(STXML*)childAtIndex:(unsigned)index;
-(STXML*)getXMLBodyByTag:(NSString*)theTag namespace:(NSString*)theNamespace index:(unsigned)index;

-(STXML*)addXMLBody:(STXML*)theObject;
-(void)addChild:(STXML*)theObject;
-(void)addTextBody:(NSString*)theText;
-(void)addTextBodyData:(NSData*)theText;
-(void)removeChildren;

The getTextBody: method retrieves textual body of the XML object. If the object does not have a text body, the method returns nil.
The childCount method returns the number of XML objects in this XML object body.
The childAtIndex: method retrieves an XML object from this XML object body, by index.
The getXMLBodyByTag:namespace:index: method retrieves an XML object from this XML object body. It retrieves the XML object with the specified Tag (or any Tag, if theTag parameter is set to nil) and the specified namespace (or any namespace, if theNamespace parameter is set to nil). As there can be several XML objects with the specified tag and namespace, the index parameter specifies which of these XML objects should be retrieved.

The addXMLBody: method adds an XML object to the XML object body. Each XML object has a reference link to its parent XML object, so you can add one XML object to only one XML object body. The method returns its parameter (the added XML object).
addChild:


CommuniGate Pro Guide. Copyright © 2020, AO StalkerSoft