我如何用PHP解析XML文件(How I can parse XML file with php)
我有一个这种格式的XML文件,我想读取产品ID和图像等数据,并希望在页面中显示它。 你看到以下链接http://mrprofessional.se/XML/INT.xml,你会看到我要解析的XML文件。 请帮我这个案子
<ICECAT-interface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://data.icecat.biz/xsd/files.index.xsd"> <files.index Generated="20131228001603"> <file path="export/freexml.int/INT/2229.xml" Product_ID="2229" Updated="20131227074205" Quality="ICECAT" Supplier_id="1" Prod_ID="C4844AE" Catid="377" On_Market="1" Model_Name="10" Product_View="223" HighPic="http://images.icecat.biz/img/norm/high/15743_2229-8075.jpg" HighPicSize="58616" HighPicWidth="400" HighPicHeight="400" Date_Added="20051023000000"> <EAN_UPCS> <EAN_UPC Value="0886985196538"/> <EAN_UPC Value="0725184755811"/> <EAN_UPC Value="5051964028635"/> <EAN_UPC Value="0088698519653"/> </EAN_UPCS> <Country_Markets> <Country_Market Value="NL"/> <Country_Market Value="BE"/> <Country_Market Value="GB"/> <Country_Market Value="DE"/> <Country_Market Value="DK"/> <Country_Market Value="ES"/> </Country_Markets> </file>
我想阅读我尝试该代码的产品ID和图像
<?php $xml = simplexml_load_file("INT.xml"); $doc = new DOMDocument(); $doc->$xml; $ie = $doc->getElementsByTagName( "ICECAT-interface" ); $iedata = $file->item(0)->nodeValue; echo $iedata; $file = $doc->getElementsByTagName( "file" ); foreach( $file as $filedata ) { $p_id = $filedata->getAttribute('Product_ID'); $highpic = $location->getAttribute('HighPic'); echo $$p_id.'-'.$highpic.'<br>'; } ?>
但它没有用,请帮我解决这个案子
I have a XML file in this format and i want to read the data such as product ID and image and want to display it in a page. of you see the following link http://mrprofessional.se/XML/INT.xml you will see the XML file which i want to parse. please help me this case
<ICECAT-interface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://data.icecat.biz/xsd/files.index.xsd"> <files.index Generated="20131228001603"> <file path="export/freexml.int/INT/2229.xml" Product_ID="2229" Updated="20131227074205" Quality="ICECAT" Supplier_id="1" Prod_ID="C4844AE" Catid="377" On_Market="1" Model_Name="10" Product_View="223" HighPic="http://images.icecat.biz/img/norm/high/15743_2229-8075.jpg" HighPicSize="58616" HighPicWidth="400" HighPicHeight="400" Date_Added="20051023000000"> <EAN_UPCS> <EAN_UPC Value="0886985196538"/> <EAN_UPC Value="0725184755811"/> <EAN_UPC Value="5051964028635"/> <EAN_UPC Value="0088698519653"/> </EAN_UPCS> <Country_Markets> <Country_Market Value="NL"/> <Country_Market Value="BE"/> <Country_Market Value="GB"/> <Country_Market Value="DE"/> <Country_Market Value="DK"/> <Country_Market Value="ES"/> </Country_Markets> </file>
I want to read the product id and image for which i tried that code
<?php $xml = simplexml_load_file("INT.xml"); $doc = new DOMDocument(); $doc->$xml; $ie = $doc->getElementsByTagName( "ICECAT-interface" ); $iedata = $file->item(0)->nodeValue; echo $iedata; $file = $doc->getElementsByTagName( "file" ); foreach( $file as $filedata ) { $p_id = $filedata->getAttribute('Product_ID'); $highpic = $location->getAttribute('HighPic'); echo $$p_id.'-'.$highpic.'<br>'; } ?>
but it s not working please help me on this case
原文:https://stackoverflow.com/questions/20831603
最满意答案
我所做的是创建空子GameObjects [每个对撞机的一个游戏对象]并为它们分配碰撞器,然后我会为那些孩子分配标签[在你的情况下,他们可以是'AlwaysActive'和'SwitchingActive'或者你能做的任何更好的名字拿出]。
然后在父母中我将使用
GetComponentsinChildren<Collider>
来查找所有碰撞器,并检查GameObject(相应碰撞器)的标签是否符合我的要求。 如果是这样,我将完成我所需的任务,否则跳过它。注意:子
OnTriggerEnter
OnCollisionEnter
在父脚本中调用OnTriggerEnter
或OnCollisionEnter
。 我使用委托策略来从子游戏对象到我的父游戏对象的冲突。What I do is create empty child GameObjects [One GameObject for every collider] and assign colliders to them, and then I would assign tags to those children [in your case they can be 'AlwaysActive' and 'SwitchingActive' or whatever better name you can come up with].
Then in the parent I will use
GetComponentsinChildren<Collider>
to find all the colliders, and check if the tag of the GameObject (of a respective collider) matches my requirement or not. If it does I will do my required task otherwise skip it.NOTE: Colliders on child GameObjects do not call
OnTriggerEnter
orOnCollisionEnter
in parent script. I use delegate strategy to get collisions from child game objects into my parent game object.
相关问答
更多-
在这些情况下我做的是添加一些Children GameObject,每个GameObject只有一个Box Collider。 您可以更改GameObjects的名称,在代码中对它们进行比较。 像这样的东西: 立方体 A面 B面 然后,在您的代码中,在您的光线投射之后,您将与之进行比较 if(hit.gameObject.name.Equals("Side A")) { //do something } What I do in these cases is to add some Childre ...
-
好吧,我做到了:),只好使用other.transform.parent.GetComponent(); 就像Nika Kasradze说的那样,然后我必须在做任何事情之前测试玩家是否为空:) 谢谢你的帮助 ! using Devdog.General; using System.Collections; using System.Collections.Generic; using UnityEngine; public class SafeZone : MonoBehaviour { pro ...
-
Unity对所有MonoBehavi和引擎命名使用C#语法。 也就是说,一个方法以封顶字母开头: void OnTriggerEnter(Collider col){} Unity uses C# syntax for all of MonoBehaviour and engine namings. That is, a method starts with cap letter: void OnTriggerEnter(Collider col){}
-
这不是如何移动Rigidbody对象并移动它可能会导致许多问题,包括您的问题中提到的问题。 具有Rigidbody对象应该使用Rigidbody组件和Rigidbody.MovePosition , Rigidbody.AddForce和Rigidbody.velocity等函数移动,而不是通过transform或transform.Translate 。 此外,您应该在FixedUpdate函数中移动Rigidbody对象而不是Update函数。 如果你正在通过变换移动其他Rigidbody对象,那么你也 ...
-
只是发布这个答案,以便它可以被关闭。 这里的问题在于,你的If语句没有大括号,不管布尔值如何评估,都会导致代码在运行后运行。 Just posting this as an answer so it can be closed. The problem here is that your If-statement has no curly braces, causing the code after it to run regardless of how the boolean evaluates.
-
您可以保留所有这些对象的列表,然后当您的事件发生时,您可以向所有对象发送消息以执行您希望他们执行的操作。 让我们假设您希望您的球体分成小块。 您向球体发送Force消息。 然后你使用牛顿运动定律,找出每件作品的速度。 记住速度是一个向量,因此它有方向。 这就是我将如何做到这一点,并仍然保持对我的游戏/模拟中发生的事情的适当控制。 记住F = ma 。 I managed to work around this by checking the distance from the selected object ...
-
对于你的第二个问题: 箭头碰撞器将触发碰撞的所有碰撞器中的碰撞,这是适当的行为。 如果你想让箭头只与一个敌人发生碰撞,你应该在箭头上创建一个脚本并使用它的OnTrigger / OnCollision来禁用它的OnCollision 。 For your second question: The arrow collider will trigger the collision in all colliders that it touches, that's the appropriate behaviou ...
-
我所做的是创建空子GameObjects [每个对撞机的一个游戏对象]并为它们分配碰撞器,然后我会为那些孩子分配标签[在你的情况下,他们可以是'AlwaysActive'和'SwitchingActive'或者你能做的任何更好的名字拿出]。 然后在父母中我将使用GetComponentsinChildren
来查找所有碰撞器,并检查GameObject(相应碰撞器)的标签是否符合我的要求。 如果是这样,我将完成我所需的任务,否则跳过它。 注意:子OnTriggerEnter OnColli ... -
在导入的对象上,您有两个转换,一个用于游戏对象,另一个用于网格。 网格的变换相对于其父游戏对象,因此在大多数情况下应该是(0,0,0): 网格对撞机非常昂贵,只能用于简单的静态对象。 如果你有一个更复杂的模型,你应该考虑使用更简单的对撞机。 On imported objects you have two tranforms, one for the game object and the other for the mesh. The mesh's transform is relative to its ...
-
Unity:相机对撞机(Unity: Camera Collider)[2022-03-04]
您需要检查哪个碰撞器与相机碰撞器碰撞,您可以使用OnColliderEnter(Collider other)类似结构来实现此OnColliderEnter(Collider other) : Collider playerCollider = GameObject.Fine("Player").GetComponent(); if (!other == playerCollider) { //Do your zooming out. } You need to check which ...