Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-20-2011, 07:47 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 25
Umaid123 is on a distinguished road
Default How to parse this XML using touch XML

Code:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetStationsResponse xmlns="http://www.example.com/">
      <GetStationsResult>
        <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
          <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
            <xs:complexType>
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="Stations">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="ID" type="xs:decimal" minOccurs="0"/>
                      <xs:element name="NAME" type="xs:string" minOccurs="0"/>
                      <xs:element name="DESCRIPTION" type="xs:string" minOccurs="0"/>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
              </xs:choice>
            </xs:complexType>
          </xs:element>
        </xs:schema>
        <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
          <NewDataSet xmlns="">
            <Stations diffgr:id="Stations1" msdata:rowOrder="0">
              <ID>129</ID>
              <NAME>Station 1</NAME>
              <DESCRIPTION>Station 1</DESCRIPTION>
            </Stations>
            <Stations diffgr:id="Stations2" msdata:rowOrder="1">
              <ID>128</ID>
              <NAME>Station 2</NAME>
            </Stations>
		</NewDataSet>
        </diffgr:diffgram>
      </GetStationsResult>
    </GetStationsResponse>
  </soap:Body>
</soap:Envelope>
I want for All <Stations> tag

Code:
-(void) grabStationData:(NSData *)responseData {
	
    if (stationEntries) {
        [self.stationEntries removeAllObjects];
    }
    // Initialize the blogEntries MutableArray that we declared in the header
    self.stationEntries = [[[NSMutableArray alloc] init] autorelease];
	
	// Create a new rssParser object based on the TouchXML "CXMLDocument" class, this is the
    // object that actually grabs and processes the RSS data
    
    CXMLDocument *rssParser = [[CXMLDocument alloc] initWithData:responseData options:0 error:nil];
    //CXMLDocument *rssParser = [[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil];
	
	NSLog(@"rssParser %@",rssParser);
	//NSLog(@"url %@",url);
	
    // Create a new Array object to be used with the looping of the results from the rssParser
    NSArray *resultNodes = NULL;
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                          @"http://www.example.com/",
                          @"tempuriStation", 
                          nil];
    
    // Set the resultNodes Array to contain an object for every instance of an  node in our RSS feed
    //resultNodes = [rssParser nodesForXPath:@"//GetImagesResult" error:nil];
    resultNodes = [rssParser nodesForXPath:@"//tempuriStation:GetStationsResult" namespaceMappings:dict error:nil];
	
    // Loop through the resultNodes to access each items actual data
    for (CXMLElement *resultElement in resultNodes) {
		
        // Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries
        NSMutableDictionary *blogItem = [[[NSMutableDictionary alloc] init] autorelease];
		
        // Create a counter variable as type "int"
        int counter;
		
        // Loop through the children of the current  node
		for(counter = 0; counter < [resultElement childCount]; counter++) {
			
			//[resultElement initWithXMLString:@""];
			NSString *strValue = [[resultElement childAtIndex:counter] stringValue];
			//strValue = [strValue stringByReplacingOccurrencesOfString:@"\n" withString:@""];
			NSString *strName = [[resultElement childAtIndex:counter] name];
            
			if ([resultNodes containsObject:@""] || resultNodes == nil || resultElement == nil || [resultElement isEqual:@""] || [resultElement children] == nil) {
				
				NSLog(@"Null Object");
			}
			else {
				
				if (strValue && strName) {
					
					// Add each field to the blogItem Dictionary with the node name as key and node value as the value
					[blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
				}
			}
        }
		
        // Add the blogItem to the global blogEntries Array so that the view can access it.
        //[self.imagesEntries setObject:[blogItem copy] forKey:@"text"];
        [self.stationEntries addObject:[blogItem copy]];
        
        NSLog(@"Station Image Entries %@",self.stationEntries);
    }
	
    //[appDelegate hideActivity:self];
	//[[rssParser retain] release];
}

Last edited by Umaid123; 10-20-2011 at 08:35 AM. Reason: Improved formatting
Umaid123 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, iphone-sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
14 members and 382 guests
13dario13, 7twenty7, buggen, EvilElf, glenn_sayers, j.b.rajesh@gmail.com, LunarMoon, morterbaher, n00b, QuantumDoja, sacha1996, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0