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