Joseph DeCarlo
Joseph DeCarlo

Reputation: 3278

NSXMLParser get namespace prefix for attribute

I have an XML structure that looks like:

<Succeeded p1:type="Edm.Boolean" xmlns:p1="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">false</Succeeded>

Since I need to be able to get the p1:type="Edm.Boolean" attribute and the namespace prefix may be different depending on several forces beyond my control. I need to figure out how to get the prefix from the namespace URI programmatically.

I have implemented the parser:didStartMappingPrefix:toURI: and parser:didEndMappingPrefix: delegate methods, and though I have set setShouldProcessNamespaces to YES, they do not get called.

I am new to NSXMLParser, but not to iOS nor XML. Any direction on how I should go about this would be greatly appreciated.

Upvotes: 2

Views: 927

Answers (1)

Joseph DeCarlo
Joseph DeCarlo

Reputation: 3278

In addition to implementing the delegate methods and calling setShouldProcessNamespaces:YES, setShouldReportNamespacePrefixes:YES should also be called.

This change will cause both "prefix" protocol methods to be called. There you can capture the namespace URI and prefix and use them as needed.

Upvotes: 3

Related Questions