如何解析不同类型的XML数据的或相似的XML结构(how to parse different ty

2019-10-23 00:13发布

我已经扫描用我的iPhone图像和获取以下类型的结果。

<?xml version="1.0" encoding="UTF-8"?>
<PrintLetterBarcodeData uid="229636134720" name="Nandan Mohan Nilekani" gender="M" 
    yob="1955" house="856, 13th Main , 3rd Block" loc="Koramangala" vtc="Bangalore South" 
    po="Koramangala" dist="Bangalore" state="Karnataka" pc="560034"/>

如何可以拆分或分析上面的XML数据的最佳方式。

Answer 1:

请检查验证码

    - (void)viewDidLoad{

[super viewDidLoad];

NSString *DataPath = @"<PrintLetterBarcodeData uid=\"229636134720\" name=\"Nandan Mohan Nilekani\" gender=\"M\" yob=\"1955\" house=\"856, 13th Main , 3rd Block\" loc=\"Koramangala\" vtc=\"Bangalore South\" po=\"Koramangala\" dist=\"Bangalore\" state=\"Karnataka\" pc=\"560034\"/>";
NSData* data=[DataPath dataUsingEncoding:NSUTF8StringEncoding];;
NSXMLParser* rssParser = [[NSXMLParser alloc] initWithData:data];

[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {

NSDictionary* dic;

currentElementValue = [[NSMutableString alloc] init];
if ([elementName isEqualToString:@"PrintLetterBarcodeData"])
{
    dic=attributeDict;
}
NSLog(@"%@",dic);}

输出:{

DIST =班加罗尔;

gender = M;

house = "856, 13th Main , 3rd Block";

loc = Koramangala;

name = "Nandan Mohan Nilekani";

pc = 560034;

po = Koramangala;

state = Karnataka;

uid = 229636134720;

vtc = "Bangalore South";

yob = 1955;

}



文章来源: how to parse different type of xml data or similar to xml structure