如何在 Cocoa 中解析 XML?

发布于 2024-12-08 09:14:34 字数 672 浏览 3 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2024-12-15 09:14:34

您可以使用此委托方法智能地访问标记中包含的值;):

 - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

此链接可能非常有用 - 处理 XML 元素和属性

You can access the value enclosed within tags by intelligently using this delegate method ;):

 - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

This link can prove to be useful - Handling XML Elements and Attributes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文