how to parse different type of xml data or similar

2019-08-09 02:02发布

I have scanned a image using my iphone and get the below type result.

<?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"/>

How can best way to split or parse the above xml data.

1条回答
来,给爷笑一个
2楼-- · 2019-08-09 03:02

Please check this code

    - (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);}

Output: {

dist = Bangalore;

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;

}

查看更多
登录 后发表回答