tags:

views:

125

answers:

1

In a nutshell, I don't want raw text, or even rich text. I want to load an xml document, which has metadata for sections of text, and I want to display that metadata in a drawer when I click on a given text section. A hyperlink is a good example; obviously trivial to do in a web app, but while I'm not that experienced with mac dev, I can't seem to find an easy way to accomplish this with cocoa.

Any suggestions as to general strategy? There doesn't seem to be an HTML view built in to Interface builder or I'd mess with that.

+2  A: 

I'm not entirely clear on what you're trying to do. It sounds like you want to load an XML document, display the text, and display various metadata when certain bits of text are selected.

If that's the case, you should read about the Cocoa Text System. The NSTextStorage class is a subclass of NSMutableAttributedString, and you can apply arbitrary attributes to any range of text. When the selection changes, you can get the attributes in the selected range and use that to update your drawer. (By the way, drawers are really on their way out. I'd suggest a different user interface. NSSplitView-based interfaces are much more in vogue these days.)

Of course, to build up the NSTextStorage, you'd need to parse the XML with NSXMLDocument or NSXMLParser, but you'd get much more control and it would look more "Cocoa-like".

You could use a WebView, which is the Safari renderer, but I think you'd have a hard time getting it to display text the way you want. Safari has never been great at rendering XML without XSLT.

Alex