0
그 같은 XML 파일이 있습니다SimpleXML을 액세스 데이터
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Items>
<Item Category="14" />
</Items>
<Events>
<Event type="EventType">
<Date>November 24, 2016</Date>
</Event>
</Events>
</Data>
을 그리고>는 항목 - 카테고리를 값 "14"싶어.
은 그 같은 시도 :echo $xml->Items->Item[0]->{@attributes}['Category'];
출력이 비어 있습니다.
난 그냥 수행 할 때 다음
SimpleXMLElement Object ([Items] => SimpleXMLElement Object ([Item] => SimpleXMLElement Object ([@attributes] => Array ([Category] => 14))) [Events] => SimpleXMLElement Object ([Event] => SimpleXMLElement Object ([@attributes] => Array ([type] => EventType) [Date] => November 24, 2016)))
내가 시도 :
print_r($xml)
내가 얻을
$p = xml_parser_create();
xml_parse_into_struct($p, $xml, $vals, $index);
xml_parser_free($p);
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);
출력은 다음과 같습니다
Index array Array () Vals array Array ()
,
XML은 그렇게 열립니다 :
$file="test.xml";
if (file_exists($file)) {
$xml = simplexml_load_file($file);
감사합니다. 출력이 비어 있습니다 :-( – swapfile
"Print_r ($ xml-> Items-> Item [0] -> {@ 속성})"에 대한 출력은 "SimpleXMLElement Object (")입니다. – swapfile
다음과 같이하십시오 (첫 번째 예). - http://php.net/manual/en/function.xml-parse-into-struct.php –