首页 \ 问答 \ 我如何用PHP解析XML文件(How I can parse XML file with php)

我如何用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
更新时间:2023-09-25 17:09

最满意答案

我所做的是创建空子GameObjects [每个对撞机的一个游戏对象]并为它们分配碰撞器,然后我会为那些孩子分配标签[在你的情况下,他们可以是'AlwaysActive'和'SwitchingActive'或者你能做的任何更好的名字拿出]。

然后在父母中我将使用GetComponentsinChildren<Collider>来查找所有碰撞器,并检查GameObject(相应碰撞器)的标签是否符合我的要求。 如果是这样,我将完成我所需的任务,否则跳过它。

注意:子OnTriggerEnter OnCollisionEnter在父脚本中调用OnTriggerEnterOnCollisionEnter 。 我使用委托策略来从子游戏对象到我的父游戏对象的冲突。


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 or OnCollisionEnter 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 ...
  • 您需要检查哪个碰撞器与相机碰撞器碰撞,您可以使用OnColliderEnter(Collider other)类似结构来实现此OnColliderEnter(Collider other) : Collider playerCollider = GameObject.Fine("Player").GetComponent(); if (!other == playerCollider) { //Do your zooming out. } You need to check which ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)