$Xml->children() 不适用于 :commons 标签 [英] $Xml->children() is not working with :commons tag

查看:21
本文介绍了$Xml->children() 不适用于 :commons 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   <listing> 
<Community>
            <commons:Subdivision commons:isgSecurityClass="Public">Cheat Crossings</commons:Subdivision>
            <commons:Schools>
                <commons:School>
                    <commons:Name>Valley View</commons:Name>
                    <commons:SchoolCategory>Elementary</commons:SchoolCategory>
                    <commons:District commons:isgSecurityClass="Public">Monongalia</commons:District>
                    <commons:Description>true</commons:Description>
                </commons:School>
                <commons:School>
                    <commons:Name>MHS</commons:Name>
                    <commons:SchoolCategory>High</commons:SchoolCategory>
                    <commons:District commons:isgSecurityClass="Public">Monongalia</commons:District>
                    <commons:Description>true</commons:Description>
                </commons:School>
                <commons:School>
                    <commons:Name>Morgantown Jr High School</commons:Name>
                    <commons:SchoolCategory>JuniorHigh</commons:SchoolCategory>
                    <commons:District commons:isgSecurityClass="Public">Monongalia</commons:District>
                    <commons:Description>true</commons:Description>
                </commons:School>
                <commons:School>
                    <commons:Name>South</commons:Name>
                    <commons:SchoolCategory>Middle</commons:SchoolCategory>
                    <commons:District commons:isgSecurityClass="Public">Monongalia</commons:District>
                    <commons:Description>true</commons:Description>
                </commons:School>
            </commons:Schools>
        </Community>

如何获取学校标签下的所有学校记录?我试过这个,但它不起作用.$eachListing->Community->Schools->children("commons",true);

How can i get all records of school under schools tag? I tried this but it's not working. $eachListing->Community->Schools->children("commons",true);

推荐答案

这里应该有一个 xmlns:commons="..." 属性.这个属性的值是实际的命名空间,'common' 前缀只是它的一个别名.在您的应用程序中使用命名空间定义变量或常量并使用它,而不是别名/前缀.

Here should be a xmlns:commons="..." attribute somewhere. The value of this attribute is the actual namespace, the 'common' prefix is just an alias for it. Define a variable or constant in your application with the namespace and use it, not the alias/prefix.

const XMLNS_COMMON = 'http://rets.org/xsd/RETSCommons'; // the value from the xmlns:common attribute?
$eachListing->Community->Schools->children(XMLNS_COMMON);

别名/前缀可以在文档中的每个节点上更改,并且不是强制性的.不要把你的逻辑建立在它上面.

The alias/prefix can be changed on each node in a document and is not mandatory. Do not base your logic on it.

可能需要对不在文档元素命名空间中的任何节点执行此操作.

It might be necessary to do this on for any node that is not in the namespace of the document element.

$nodes = $eachListing
  ->Community
  ->children(XMLNS_COMMON)->Schools
  ->children(XMLNS_COMMON);

演示:https://eval.in/205950

这篇关于$Xml->children() 不适用于 :commons 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆