如何在 Cocoa 中解析 XML?
我正在尝试使用 NSXMLParser 来使用 cocoa 解析 xml 文件,如下所示。
<UserDetails>
<Name>John Doe</Name>
<UserName>jdoe</UserName>
<Password>supersecretpass</Password>
</UserDetails>
现在我使用的方法如下:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(@"MEthod came here");
if ([elementName isEqualToString:@"Name"]) {
NSLog(@"Name :");
}
}
我想检索 elementName 标记中包含的值。我该怎么做..该方法正在被调用,但我无法检索 XML 标签值中包含的值。
I am Trying To Use NSXMLParser to parse an xml file using cocoa which goes like this..
<UserDetails>
<Name>John Doe</Name>
<UserName>jdoe</UserName>
<Password>supersecretpass</Password>
</UserDetails>
Now i am using the method as follows:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(@"MEthod came here");
if ([elementName isEqualToString:@"Name"]) {
NSLog(@"Name :");
}
}
I want to retrieve the values contained in the elementName tag. How do i do it..The method is being called but i am unable to retrieve the value contained within the tag values of XML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此委托方法智能地访问标记中包含的值;):
此链接可能非常有用 -
处理 XML 元素和属性
You can access the value enclosed within tags by intelligently using this delegate method ;):
This link can prove to be useful -
Handling XML Elements and Attributes