# XML-DOM in Objective-C



## iconara (Jun 12, 2002)

Is anyone interested in a XML Document Object Model framework written in Objective-C? It was inspired largely by JDOM (www.jdom.org). I wrote it for my own curiosity, but I think it could be of use. There seems to be a lack of this for Cocoa, there are a few for C++, but none for ObjC, what I have seen.

Anyone?

It can parse XML-files into DOM-trees with Apples XML-services (from the CoreFoundation), namespaces are a little buggy still, though.

This is what you can do (a trivial example):


```
DOMDocument *doc = [[DOMDocument alloc] init];
DOMElement *elem1 = [[DOMElement alloc] initWithName:@"iconara"];
DOMElement *elem2 = [[DOMElement alloc] initWithName:@"monkeyboxing"];

[doc setRootElement:elem1];
[elem1 addContent:elem2];
[elem2 setEmpty:YES];
[elem2 addAttribute:[DOMAttribute attributeWithName:@"foo" Value:@"bar"]];

printf( [[doc toString] cString] );

[elem2 release];
[elem1 release];
[doc release];
```

and you get:


```
&lt;?xml version="1.0"?&gt;

&lt;iconara foo="bar"&gt;
    &lt;monkeyboxing/&gt;
&lt;/iconara&gt;
```

I'll post it if you what it.

happy coding

theo


----------

