Click here to Skip to main content
15,891,431 members

parsing xml in iphone not gettig value

cutie1 asked:

Open original thread
Hii

I need to call a XML file from a WCF Service and Parse the content of XML in iPhone.
I m able to call the service url but when doing parsing using NSXMLParser I couldn't get a patricular attribute value in XML .I m using a ViewController application in XCode.

My XML file is like this :
HTML
<GetCompanyResponse xmlns="http://schemas.datacontract.org/2004/07/DomainModel" xmlns:i="http://www.w3.org/2001/XMLSchema-
<CompanyList>
  <Company>
     <Id>b9ca2e32-ce88-4d72-99ce-9bc592511e85</Id>
  </Company>
</CompanyList>


I have tried this code :
CSS
NSString *urlString = [NSString stringWithFormat:@"http://192.168.0.107:8732/Design_Time_Addresses/IServices/
AppointmentService/json/GetCompany";
NSURL *jsonUrl =[NSURL URLWithString:urlString];

C#
 NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:jsonUrl];
    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];
    
    [parser parse];
    [parser release];  

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qName attributes:(NSDictionary *)attributeDict
{
        
    if ([elementName isEqualToString:@"Company"]) {
        NSString *name=[attributeDict objectForKey:@"Id"];
      
    }
}


But when I check for the value in 'name' it is returning nil.Couldn't get where I m I going wrong?What should I change?How can I get the value in ID attribute?

Any help would be appreciated..

Thanks in advance..
Tags: Mobile Apps (iPhone)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900