iPhone XMLReader SOAP 响应解析
我对 XMLReader 的输出有问题,它应该能够将任何 SOAP-Result 解析为 NSDictionary。
当我查看结果时,我得到以下结果:
键:soapEnvelope,值:{xml 文件的其余部分到末尾,带有所有标签,但它似乎是一个长字符串}
什么我在这里做错了吗,因为我希望获得一个以所有 XML 标签作为键的 NSDictionary ?
编辑:由于我几天来一直在努力理解这一点,我可能完全走错了方向,所以如果可能的话......这是我的 XML:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetData2Response xmlns="http://tempuri.org/">
<GetData2Result>
<NoOfObjectsDetected>1</NoOfObjectsDetected>
<RectanglesForPicture>
<Rectangle>
<Location>
<X>90</X>
<Y>14</Y>
</Location>
<Size>
<Width>352</Width>
<Height>352</Height>
</Size>
<X>90</X>
<Y>14</Y>
<Width>352</Width>
<Height>352</Height>
</Rectangle>
</RectanglesForPicture>
<ReturnMessage>Juhu!</ReturnMessage>
</GetData2Result>
</GetData2Response>
</soap:Body>
当我想要在 int 中使用 NoOfObjectsDetected 时 - 我到底需要做什么? (这很愚蠢,我知道......但我迷失了atm......谢谢)
I have problems regarding the output of the XMLReader , which should be able to parse any SOAP-Result into an NSDictionary.
When I go through the results I get the following:
Key: soapEnvelope, Value: {the rest of the xml-file to the end, with all tags, but it seems to be a long string}
What am I doing wrong here since I expected to get a NSDictionary with all of my XML-Tags as a key?
Edit: Since I´m working and trying to understand this since days, I may be totally in the wrong direction, so if possible... here´s my XML:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetData2Response xmlns="http://tempuri.org/">
<GetData2Result>
<NoOfObjectsDetected>1</NoOfObjectsDetected>
<RectanglesForPicture>
<Rectangle>
<Location>
<X>90</X>
<Y>14</Y>
</Location>
<Size>
<Width>352</Width>
<Height>352</Height>
</Size>
<X>90</X>
<Y>14</Y>
<Width>352</Width>
<Height>352</Height>
</Rectangle>
</RectanglesForPicture>
<ReturnMessage>Juhu!</ReturnMessage>
</GetData2Result>
</GetData2Response>
</soap:Body>
When I want to have Lets say NoOfObjectsDetected in an int - what exactly do I have to do? (It´s stupid, I know... but I´m lost atm... thx)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你在 NSXMLParser 的帮助下解析吗?这是方法。创建一个可变数组来存储 xml 的内容。在委托方法中执行以下操作:
nsmutablearray noOfObjetcsArray;
nsstring 元素名称Str;
-(void)解析器:(NSXMLParser *)解析器didStartElement:(NSString *)elementName命名空间URI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName 属性:(NSDictionary *)atributeDict
{
if ([elementName isEqualToString:@"NoOfObjectsDetected"])
{
noOfObjetcsArray =[nsmutablearray alloc] initwithcapacity:0];
元素名称Str = 元素名称;
}
}
-(void)parser:(NSXMLParser *)parserfoundCharacters:(NSString *)string
{
if ([elementNameStr isEqualToString:@"NoOfObjectsDetected"])
{
}
}
解析完成后,您将获得数组中的内容。因为你希望它作为一个 int 值,所以无论你在哪里使用这个值,只需给出:
[[noOfObjetcsArray objectAtIndex:0] intValue]
这会将字符串转换为 int 值。这就是你获得价值的方式。尝试一下。
一切顺利 :)
}
are u parsing with the help of NSXMLParser?? here is the method. create an mutable array to store the contents of xml. in the delegate methods do the following:
nsmutablearray noOfObjetcsArray;
nsstring elementNameStr;
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)atributeDict
{
if ([elementName isEqualToString:@"NoOfObjectsDetected"])
{
noOfObjetcsArray =[nsmutablearray alloc] initwithcapacity:0];
elementNameStr = elementName;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([elementNameStr isEqualToString:@"NoOfObjectsDetected"])
{
}
}
when parsing is complete u will get the contents in the array. since u want it as an int value, wherever u use this value jus give:
[[noOfObjetcsArray objectAtIndex:0] intValue]
this will convert string to int value. thats the way u can get teh value. try it.
all the best :)
}
这里 elementsValues 是 NSMutableDictionary 的类型。 currentElementsValue 是当前标签的值。 elementName 是当前标签。如果不清楚,请随时提问
Here elementsValues is type of NSMutableDictionary. currentElementsValue is the value of current tag. And elementName is current tag. Free to ask questions if this is not clear