-1

私はこれを行う方法を知っていますが、私の要素名は同じprakeshであり、すべての属性名も同じであるため、prakesh要素の属性値を取得する方法をtableview説明してください:

<?xml version="1.0" encoding="UTF-8"?>
    <prakesh ConfigVersion="1">
        <prakesh ProductId="{ec8e531b-6873-4819-8ade-501f6dc6ff42}" ProductVersion="1.0" ProductLogo="" ProductName="4x6_Glossy" ProductRefImage="4x6_Glossy.png" CustomerType="1" Dpi="300" Unit="0" CoverType="1" CoverWidth="16.5" CoverHeight="12" CoverTopMargin="0.3" CoverBottomMargin="0.3" CoverLeftMargin="0.3" CoverRightMargin="0.3" PageWidth="4" PageHeight="6" PageTopMargin="0.3" PageBottomMargin="0.3" PageLeftMargin="0.3" PageRightMargin="0.3" Comments="4 x 6 Inches" BasePrice="10" PricePerPage="0" BasePriceWithDesign="0" PricePerPageWithDesign="0" FixQuantity="0" Finish="Glossy" ServiceName="Photoprints"/>
        <prakesh ProductId="{6e5b2453-f0e2-43c8-a7d6-1900346b9f83}" ProductVersion="1.0" ProductLogo="" ProductName="4x6_Matt" ProductRefImage="4x6_Matt.png" CustomerType="1" Dpi="300" Unit="0" CoverType="1" CoverWidth="16.5" CoverHeight="12" CoverTopMargin="0.3" CoverBottomMargin="0.3" CoverLeftMargin="0.3" CoverRightMargin="0.3" PageWidth="4" PageHeight="6" PageTopMargin="0.3" PageBottomMargin="0.3" PageLeftMargin="0.3" PageRightMargin="0.3" Comments="4 x 6 Inches" BasePrice="10" PricePerPage="0" BasePriceWithDesign="0" PricePerPageWithDesign="0" FixQuantity="0" Finish="Matt" ServiceName="Photoprints"/>
</prakesh>

これを行いましたが、最初のprakesh productidとすべてしか取得していません。2つ目はどうやって手に入れる?これが私のコードです:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    NSLog(@"Name:%@",elementName);
    _forecastInfo.ProductId = [attributeDict objectForKey:@"ProductId"];
    _forecastInfo.ProductName = [attributeDict objectForKey:@"ProductName"];
    _forecastInfo.ProductRefImage=[attributeDict objectForKey:@"ProductRefImage"];
    _forecastInfo.CustomerType=[attributeDict objectForKey:@"CustomerType"];
    _forecastInfo.Dpi=[attributeDict objectForKey:@"Dpi"];
    _forecastInfo.Unit=[attributeDict objectForKey:@"Unit"];
    _forecastInfo.CoverType=[attributeDict objectForKey:@"CoverType"];
    _forecastInfo.CoverWidth=[attributeDict objectForKey:@"CoverWidth"];
     _forecastInfo.CoverHeight=[attributeDict objectForKey:@"CoverHeight"];



    if(_forecastInfo.ProductId||_forecastInfo.ProductName||_forecastInfo.ProductRefImage||_forecastInfo.CustomerType||_forecastInfo.Dpi|| _forecastInfo.Unit||_forecastInfo.CoverType||_forecastInfo.CoverWidth||_forecastInfo.CoverHeight)
    {
        //[productIdArray addObject:productId];
        [parser abortParsing];
        NSLog(@"%@",[_forecastInfo description]);
        if(delegate)
            [delegate forecastInfoParser:self parsed:_forecastInfo];
        [_forecastInfo release];
    }

}
4

1 に答える 1

0

以下をせよ:

  • 球体を作成しますNSMutableArray(名前を付けましょうdataArray)
  • 今のようにそれを開始します

    dataArray = [[NSMutableArray alloc] init]; //(非 ARC 環境を使用している場合は解放します。)

  • 今あなたの方法で:

    -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *) attributeDict
     {
         NSLog(@"Name:%@",elementName);
         _forecastInfo.ProductId = [attributeDict objectForKey:@"ProductId"];
         _forecastInfo.ProductName = [attributeDict objectForKey:@"ProductName"];
         _forecastInfo.ProductRefImage=[attributeDict objectForKey:@"ProductRefImage"];
         _forecastInfo.CustomerType=[attributeDict objectForKey:@"CustomerType"];
         _forecastInfo.Dpi=[attributeDict objectForKey:@"Dpi"];
         _forecastInfo.Unit=[attributeDict objectForKey:@"Unit"];
         _forecastInfo.CoverType=[attributeDict objectForKey:@"CoverType"];
         _forecastInfo.CoverWidth=[attributeDict objectForKey:@"CoverWidth"];
         _forecastInfo.CoverHeight=[attributeDict objectForKey:@"CoverHeight"];
         if(_forecastInfo.ProductId||_forecastInfo.ProductName||_forecastInfo.ProductRefImage||_forecastInfo.CustomerType||_forecastInfo.Dpi|| _forecastInfo.Unit||_forecastInfo.CoverType||_forecastInfo.CoverWidth||_forecastInfo.CoverHeight)
         {
             //[productIdArray addObject:productId];
             //[parser abortParsing];
            [dataArray addObject:[_forecastInfo copy]];
             NSLog(@"%@",[_forecastInfo description]);
            if(delegate)
                [delegate forecastInfoParser:self parsed:_forecastInfo];
            [_forecastInfo release];
         }
    }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
        if ([elementName isEqual:@"prakesh"]){
            [parser abortParsing];
        }
    }
    
  • tableViewを使用してデータを入力しdataArrayます。

于 2013-02-25T09:04:29.057 に答える