[英]XML Data Search PHP
我想通过 Id="722"、SectionId="1" 和 ClassNo="1" 获取数据。
当我搜索 Id 和 SectionId 时,我得到了数据,但我不知道如何包含 ClassNo。
这是我的 PHP 代码
$students = $xml->xpath("//Student[@Id=" . $studentid . "][@SectionId=" . $sectionid . "]");
这是我的 XML
<XML>
<Students>
<Student Id="722" SectionId="1">
<AdmissionNo>1363</AdmissionNo>
<Name>AADITRI K S</Name>
<ClassNo>1</ClassNo>
<Course>Std-VIII</Course>
<Division>VIII B</Division>
<GName>Satheesh K S</GName>
<GMobileno>70707077070</GMobileno>
<GPhone>8080808</GPhone>
<HGroup/>
<Address>Lorem Ipsum</Address>
<LoginId>1363</LoginId>
<LoginPwd>15382</LoginPwd>
<DOB>24/Dec/2006</DOB>
<BloodGroup/>
<FatherName>Satheesh K S</FatherName>
<FatherMobileno/>
<MotherName>Sini Satheesh</MotherName>
<MotherMobileno/>
<Disability/>
<DisabilityOrderNo/>
<Height> </Height>
<Weight> </Weight>
<VisionL/>
<VisionR/>
<Teeth/>
<OralHygiene/>
<Ailment/>
<Terminated>N</Terminated>
<bus>BUS 4</bus>
</Student>
</Students>
</XML>
您可以搜索 XML 列表项,其索引号为学生数组中的学生索引号([0] 或 [1] [2] 等)。 然后使用箭头 ( -> ) 和您需要的键名:
<?php
$xml = simplexml_load_file('test.xml');
$students = $xml->xpath("//Student[@Id=" . "722" . "][@SectionId=" . "1" . "]");
echo($students[0] -> ClassNo);
echo($students[0] -> Course);
echo($students[0] -> DOB);
?>
我不确定您要查找的数据到底是什么,但是,例如,如果您要获取该学生母亲的姓名,请尝试以下操作:
$students = $xml->xpath("//Student[@Id=$studentid][@SectionId=$sectionid][./ClassNo[$classno]]/MotherName");
echo $students[0];
Output 应该是
Sini Satheesh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.