$Xml->children() is not working with :commons tag

走远了吗. 提交于 2019-12-08 09:35:37

问题


   <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>

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);


回答1:


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);

Demo: https://eval.in/205950



来源:https://stackoverflow.com/questions/26366925/xml-children-is-not-working-with-commons-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!