XML 파일의 형식에 따라 :
다음 테스트 파일을 기반으로
<?php
$dom = new DOMDocument();
$dom->load('1.xml');
foreach ($dom->getElementsByTagName('article') as $node) {
// your conditions to find out the id
$id = $node->getAttribute('id');
}
$dom = new DOMDocument();
$dom->load('2.xml');
$xpath = new DOMXPath($dom);
$element = $xpath->query("//*[@id='".$id."']")->item(0);
// would echo "top_2" based on my example files
echo $element->getAttribute('name');
가정 할 경우 :
<xml>
<roomTypeCode>
<stuff>stuff</stuff>
<name>Skunkman</name>
</roomTypeCode>
<roomTypeCode>
<stuff>other stuff</stuff>
<name>Someone Else</name>
</roomTypeCode>
</xml>
그것은이 같은 것이다 : 그것은 일치 할 때,
XML 파일에 연결
$xml = simplexml_load_file('xmlfile.xml');
for($i = 0; $i < count($xml->roomTypeCode); $i++)
{
if($xml->roomTypeCode[$i]->stuff == "stuff")
{
$name = $xml->roomTypeCode[$i]->name;
}
}
이, 얼마나 많은 roomTypeCode 항목이 발견은 내 "물건"의 값을 검색하고 제대로, 당신은 그 XML 항목과 관련된 모든 것을 액세스 할 수 있습니다.
웹 페이지 (http://php.net/manual/en/class.domdocument.php)에서 자바 스크립트와 비슷한 방식으로 XML 파일과 상호 작용할 수 있습니다. DOMDocument 객체는 getElementById() 메서드를 지원합니다. – CBusBus