gpt4 book ai didi

iphone - 我有 XML 喜欢遵循如何使用 touchXML 解析,我想为 26400174350 获取像 26400174350 这样的数据

转载 作者:行者123 更新时间:2023-12-01 19:19:13 24 4
gpt4 key购买 nike

  <p231:getTraceDataReturn>
<p231:proNum>26400174350</p231:proNum>
<p231:proDate>05/13/2011</p231:proDate>
<p231:statusCode>DEL</p231:statusCode>
<p231:status>Delivered</p231:status>
<p231:appointment/>
<p231:pieces>7</p231:pieces>
<p231:weight>1082</p231:weight>
<p231:po/>
<p231:bol/>
<p231:trailer/>
<p231:signature>BARNES</p231:signature>
<p231:origTerminal>BIS</p231:origTerminal>
<p231:origAddress>2300 VERMONT AVE</p231:origAddress>
<p231:origState>ND</p231:origState>
<p231:origName>BISMARCK, ND</p231:origName>
<p231:origCity>BISMARCK</p231:origCity>
<p231:origZip>58504</p231:origZip>
<p231:origPhone>(866) 466-5031</p231:origPhone>
<p231:origFax>(701) 223-3790</p231:origFax>
<p231:destTerminal>RKI</p231:destTerminal>
<p231:destAddress>320 31ST AVE</p231:destAddress>
<p231:destState>IL</p231:destState>
<p231:destName>ROCK ISLAND, IL</p231:destName>
<p231:destCity>ROCK ISLAND</p231:destCity>
<p231:destZip>61201</p231:destZip>
<p231:destPhone>(800) 728-6806</p231:destPhone>
<p231:destFax>(309) 794-1496</p231:destFax>
<p231:delivered>Y</p231:delivered>
<p231:url/>
<p231:type>P</p231:type>
<p231:scac/>
<p231:errorMessage/>
<p231:guaranteed>N</p231:guaranteed>
<p231:call>N</p231:call>
</p231:getTraceDataReturn>

最佳答案

如果您不介意使用 NSXMLParser ...这是一个完整的类代码,可以获取所有 <p231:pronum> NSArray 上的数据和存储为你:

标题:

@interface MyParser : NSObject <NSXMLParserDelegate> {
NSMutableArray *nodeArray;
NSMutableString *nodeString;
}

+(NSArray*)parseNodeData:(NSData*)data;
-(NSArray*)nodes;
-(void)parseWithData:(NSData*)data;
@end

执行:
@implementation MyParser

+(NSArray*)parseNodeData:(NSData*)data {
NSArray *ret;
MyParser *parser = [[MyParser alloc] init];
[parser parseWithData:data];
ret = [parser nodes];
[parser release];
return(ret);
}

-(NSArray*)nodes {
if (nodeArray == nil)
return(nil);
return([NSArray arrayWithArray:nodeArray]);
}

-(void)dealloc {
[nodeArray release];

[super dealloc];
}

-(void)parseWithData:(NSData*)data {
NSXMLParser parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
[parser parse];
[parser release];
}

#pragma mark - NSXMLParserDelegate methods
-(void)parserDidStartDocument:(NSXMLParser*)parser {
if (nodeArray != nil)
[nodeArray release];

nodeArray = [[NSMutableArray alloc] init];
[nodeString release];
nodeString = nil;
}

-(void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName attributes:(NSDictionary*)attributeDict {
[nodeString release];
nodeString = [[NSMutableString alloc] init;
}

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string {
[nodeString appendString:string];
}

-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName {
if ([elementName compare:@"p231:pronum" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
[nodeArray addObject:[NSString stringWithString:nodeString]];
}

[nodeString release];
nodeString = nil;
}

@end

这可以在 NSArray 上提供您的数据只有一个方法调用(假设您的 XML 在 NSData 对象上)。

关于iphone - 我有 XML 喜欢遵循如何使用 touchXML 解析,我想为 <p231 :proNum>26400174350</p231:proNum> 获取像 26400174350 这样的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11137765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com