如何使用PHP解析此XML?(How to parse this XML using PHP?)
我想为网址解析XML: http : //www.opencellid.org/cell/get ?key = myapikey&mcc = 250&mc = 99&cellid = 29513&lac = 0
我是PHP的初学者,尝试了如下代码:
$ url =“ http://www.opencellid.org/cell/get?key=myapikey&mcc=250&mnc=99&cellid=29513&lac=0 ”;
$ xml = simplexml_load_file($ url)或die(“feed not loading”);
的print_r($ XML);
后续代码var_dump($ XML);
我想为每个属性做回声,例如lat,lon,range ..对于这个XML url。
我在stackoverflow中发现了许多资源,XML非常标准。 我找不到用于这种XML格式的示例:
任何人都可以给我一个想法? 谢谢。
I would like to do parse XML for the url: http://www.opencellid.org/cell/get?key=myapikey&mcc=250&mnc=99&cellid=29513&lac=0
I am the beginner of PHP and tried the code as below:
$url = "http://www.opencellid.org/cell/get?key=myapikey&mcc=250&mnc=99&cellid=29513&lac=0";
$xml = simplexml_load_file($url) or die("feed not loading");
print_r($xml);
var_dump($xml);
I would like to do echo for each attribute e.g. lat, lon, range.. for this XML url.
I found many resource in stackoverflow which the XML is quite standard. I cannot find an example which is used for this format of XML:
Anyone could give me an idea? Thanks.
原文:https://stackoverflow.com/questions/15611367
最满意答案
你问:
这个可以吗?
很大程度上,是的。
更准确地说,这取决于您的需求/意图。 如果您需要继续运行以使您的应用程序正常运行(例如,您可能正在转换并保存一些图像),那么您肯定需要一个强大的参考,以便它完成)。
但如果您不需要继续执行,那么您将使用
weakSelf
模式。 例如,假设您在视图控制器中有一系列调度任务,这些任务仅用于以后触发UI更新。 在这种情况下,如果视图控制器被解除,您可能不需要运行这些块,并且您当然不希望它挂起到视图控制器以获取已被解雇的视图。 (您甚至可能希望在取消视图控制器时取消这些已分派的项目,但这是另一个主题。)底线,这取决于你的意图。
You ask:
Is this okay?
Largely, yes.
More accurately, it depends upon your needs/intent. If you need this to continue to run for your app to function properly (e.g. maybe you're converting and saving some images), then you definitely want a strong reference so that it finishes).
But if you don't need to continue to execute, then you'd use
weakSelf
pattern. For example, imagine you had a series of dispatched tasks in a view controller that were there solely to later trigger UI updates. In that case, if the view controller was dismissed, you might not need these blocks to run, and you certainly wouldn't want it to hang on to the view controller for a view that was long since dismissed. (You might even want to cancel those dispatched items when the view controller was dismissed, but that's another topic.)Bottom line, it depends upon your intent.
相关问答
更多-
内存泄漏时使用回调(memory leak when using callback)[2022-06-08]
内存管理并没有什么不同,因为您使用的是异步回调。 myArchive应该是您正在执行此操作的任何类的属性。您希望它坚持到任务完成为止,对吗? @property (retain) MyClass *myArchive; 然后.. myArchive = [[MyClass alloc] init]; void (^on_success_callback)(void) = ^(void){ NSLog(@"success"); self.myArchive = nil; }; 您需要确保 ... -
你问: 这个可以吗? 很大程度上,是的。 更准确地说,这取决于您的需求/意图。 如果您需要继续运行以使您的应用程序正常运行(例如,您可能正在转换并保存一些图像),那么您肯定需要一个强大的参考,以便它完成)。 但如果您不需要继续执行,那么您将使用weakSelf模式。 例如,假设您在视图控制器中有一系列调度任务,这些任务仅用于以后触发UI更新。 在这种情况下,如果视图控制器被解除,您可能不需要运行这些块,并且您当然不希望它挂起到视图控制器以获取已被解雇的视图。 (您甚至可能希望在取消视图控制器时取消这些已分派 ...
-
删除节点会导致保留周期(Removing nodes causes retain cycles)[2023-07-08]
不是你问的问题的直接答案,而是...... 如何保留可重用节点池? 不是在死亡时移除节点,而是将其hidden属性设置为true并将其添加到重用队列。 首先尝试使现有节点出列,而不是始终创建新节点。 I've figured out how to stop the retain cycles. I had to give the action a key so then instead of removing all actions I'm only removing the action for key. ... -
getCombineIdAndNames非常好。 您正在alloc字典并在返回之前自动释放它。 没错。 这会告诉我内存泄漏是由gObjAppDelegatePtr实例引起的。 要么是它没有释放它的财产,要么整个物体都被泄露了。 另外,在getCombineIdAndNames可以改进的一件事是使用NSMutableDictionary的便捷构造函数来完全避免所有的alloc / release调用。 您还可以使用新的Obj-C容器语法: -(NSMutableDictionary *)getCombineI ...
-
什么导致这种内存泄漏?(What's causing this memory leak?)[2023-09-17]
你是如何从你的各种视图控制器上退出的? 我注意到你提到,当游戏结束时,你将另一个VC推入堆栈,但我认为这个VC链将在某个时候放松回到你的初始菜单? (实际上,我想知道你是否只是在循环,因此每次玩游戏时都会增加新的VC。) 要创建一个un-wind segue,只需在目标 VC(即:主菜单)中创建一个空方法,如下所示: - (IBAction)unwindToMainMenu:(UIStoryboardSegue*)sender { // Intentional NOP } (注意:确保它也列在标题 ... -
每次更改方向时,Android都会创建并启动新活动。 内存泄漏是由于垃圾收集器无法收集不再需要的旧活动,因为单独的线程仍在运行,并且 - 作为内部类 - 正在保留活动。 要消除内存泄漏,您需要在销毁活动时停止并结束单独的线程。 boolean stopThread; private void updateTimerAndSeekBar() { stopThread = false; Thread updater = new Thread() { ... ...
-
不,您不需要在onDestroy中将位图设置为null。 特别是如果您正在使用来自资源的图像,那么无论如何都会在Resources中保留这些参考。 你可能想要考虑的是使用StateDrawable并改变状态而不是一直切换drawable ,只是为了你自己的理智。 但是这种用法不应该导致OOM,除非你有很多图像或其他问题。 No, you do not need to set bitmaps to null in onDestroy. Especially not if you're using images ...
-
SecItemCopyMatching将属性复制到attrResult 由于您有副本,因此您有责任在某些时候发布它: CFRelease(attrResult) “ 核心基础内存管理指南”中对此进行了描述 SecItemCopyMatching copies an attribute into attrResult Since you have a copy, you are responsible for releasing it at some point with: CFRelease(attrRe ...
-
否 - weakObserver会weak ,所以如果observer被释放,它将自动nil ,但是如果addObserver:...保留观察者,那么它将保留观察者。 对象中没有关于先前引用所持有的方式的历史,它是控制自己行为的引用本身。 但是, NSNotificationCenter不保留观察者,观察者几乎从不保留通知中心。 没有保留周期。 你所引用的文字或多或少都是这样说的:存储在通知中心内的指针将变得悬而未决,即它没有断言所有权。 你所做的也不会使存储在中心内的引用自动nil 。 从iOS 9和OS ...
-
就像我在你上一篇文章中所说,细节很重要。 非MFC dll在MFC dll之前加载,如果在MFC退出之前没有释放任何数据,MFC会错误地将此报告为内存泄漏。 这是一个已知问题 ,当使用opencv和mfc时会出现问题。 解决方案是: 静态链接MFC库(最常见的方式) 尝试解决方法强制首先在上面的链接中加载mfc dll 如本问题所示延迟加载dll。 Like I said in your last post, the details are important. The non-MFC dll loads ...