Note that there are some explanatory texts on larger screens.

plurals
  1. PONSXML Parser returns blank Results
    primarykey
    data
    text
    <p>I'm currently developing an iOS App (target=iPod touch) for displaying some information, which are based in a PostgreSQL database and I'm a very beginner. I did a lot of research, but I found nothing, which really helped for fixing my problem.</p> <p>At the moment I get my data from a php file, which is the "bridge" between the iOS App and the database. For that purpose I use a http-request for asking the php file for data in xml format. Inside the php file I use</p> <pre><code>SELECT query_to_xml('".$queryString."', false, true, '') as xml </code></pre> <p>to get a xml file in return.</p> <p>So far everything works fine, so that I have a string variable with the xml result from the query available in my iOS App.</p> <p><strong>This is what I get:</strong></p> <pre><code>&lt;row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;id&gt;4&lt;/id&gt; &lt;invnr&gt;61821B741AEBI8&lt;/invnr&gt; &lt;art&gt;c&lt;/art&gt; &lt;type_id&gt;2&lt;/type_id&gt; &lt;rechnung&gt;&lt;/rechnung&gt; &lt;standort&gt;G01E01R01&lt;/standort&gt; &lt;erstellt&gt;2011-12-06&lt;/erstellt&gt; &lt;gekauft&gt;2003-01-01&lt;/gekauft&gt; &lt;/row&gt; </code></pre> <p>In objective-c I would like to have two arrays:</p> <p><strong>caption array</strong></p> <p>The first array should hold the captions from the xml file (id, invnr, art, type_id, rechnung, standort, erstellt, gekauft). The entry "row" should not be inside the array.</p> <p><strong>value array</strong></p> <p>The second array should only save the values- also the empty ones. In that example it would be 4, 61821B741AEBI8, c, 2, , G01E01R01, 2011-12-06, 2003-01-01</p> <p><strong>Using the NSXML Parser</strong></p> <p>This is the config, which I use currently for parsing the xml and for saving the data into the arrays.</p> <p><strong>Parser didStartElement</strong></p> <pre><code>-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ element = [[NSMutableString alloc] init]; if(!dataCaptions){ dataCaptions = [[NSMutableArray alloc]init]; } if([elementName isEqualToString:@"id"] || [elementName isEqualToString:@"invnr"] || [elementName isEqualToString:@"art"] || [elementName isEqualToString:@"type_id"] || [elementName isEqualToString:@"rechnung"] || [elementName isEqualToString:@"standort"] || [elementName isEqualToString:@"erstellt"] || [elementName isEqualToString:@"gekauft"]){ [element setString:elementName]; [dataCaptions addObject:elementName]; } } </code></pre> <p><strong>Parser foundCharacters</strong></p> <pre><code>-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if(!dataValues){ dataValues = [[NSMutableArray alloc]init]; } BOOL copy; if([element isEqualToString:@"id"] || [element isEqualToString:@"invnr"] || [element isEqualToString:@"art"] || [element isEqualToString:@"type_id"] || [element isEqualToString:@"rechnung"]|| [element isEqualToString:@"standort"] || [element isEqualToString:@"erstellt"] || [element isEqualToString:@"gekauft"]){ copy = YES; }else{ copy = NO; } if(copy){ [dataValues addObject:string]; NSLog(@"Found: %@ with value: %@", element, string); } } </code></pre> <p><strong>Parser didEndElement</strong></p> <pre><code>-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ } </code></pre> <p><strong>Output and Problem</strong></p> <p>The problem is that the parser seems to go several times through an element. That causes that my value array seems like that:</p> <pre><code> 2013-03-14 12:54:54.591 BarcodeScanner[582:907] Array Values( 4, "\n ", 61821B741AEBI8, "\n ", c, "\n ", 2, "\n ", "\n ", G01E01R01, "\n ", "2011-12-06", "\n ", "2003-01-01", "\n" ) </code></pre> <p>The output is also a bit complicated. Is my though wrong that the parser first take the starting xml-tag eg. (Parser didStartElement) ,than reads in the values 4 (Parser foundCharacters) and at least reads (Parser didEndElement) ?</p> <p>I hope there is somebody who could help to solve that issue. Thanks and best greetings- Tobias</p> <pre><code>2013-03-14 12:54:54.423 BarcodeScanner[582:907] Found: id with value: 4 2013-03-14 12:54:54.425 BarcodeScanner[582:907] Found: id with value: 2013-03-14 12:54:54.426 BarcodeScanner[582:907] Found: invnr with value: 61821B741AEBI8 2013-03-14 12:54:54.428 BarcodeScanner[582:907] Found: invnr with value: 2013-03-14 12:54:54.430 BarcodeScanner[582:907] Found: art with value: c 2013-03-14 12:54:54.432 BarcodeScanner[582:907] Found: art with value: 2013-03-14 12:54:54.444 BarcodeScanner[582:907] Found: type_id with value: 2 2013-03-14 12:54:54.446 BarcodeScanner[582:907] Found: type_id with value: 2013-03-14 12:54:54.448 BarcodeScanner[582:907] Found: rechnung with value: 2013-03-14 12:54:54.450 BarcodeScanner[582:907] Found: standort with value: G01E01R01 2013-03-14 12:54:54.451 BarcodeScanner[582:907] Found: standort with value: 2013-03-14 12:54:54.454 BarcodeScanner[582:907] Found: erstellt with value: 2011-12-06 2013-03-14 12:54:54.456 BarcodeScanner[582:907] Found: erstellt with value: 2013-03-14 12:54:54.461 BarcodeScanner[582:907] Found: gekauft with value: 2003-01-01 2013-03-14 12:54:54.464 BarcodeScanner[582:907] Found: gekauft with value: </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload