の
new .xml に xml データを配置し、データの単一フィールドが必要な場合は以下のコードを実行します
<?php
$file="new.xml";
function contents($parser, $data){
echo $data;
}
function startTag($parser, $data){
echo "<b>";
}
function endTag($parser, $data){
echo "</b><br />";
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
$xml = simplexml_load_string( $data);
$xml->registerXPathNamespace( 'soap', 'http://schemas.xmlsoap.org/soap/envelope/' );
$result = $xml->xpath('//soap:Body');
foreach ($result as $body) {
echo $body->ProcessPaymentResponse->ProcessPaymentResult->ResponseCode . "<br />";
echo $body->ProcessPaymentResponse->ProcessPaymentResult->ResponseDescription . "<br />";
}
?>
n個のデータが必要な場合は、これを試してください
<?php
$file="new.xml";
function contents($parser, $data){
echo $data;
}
function startTag($parser, $data){
echo "<b>";
}
function endTag($parser, $data){
echo "</b><br />";
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($file, "r");
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
$xml = simplexml_load_string($data);
$xml->registerXPathNamespace('soap:Envelope', 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//soap:Envelope:ResponseCode') as $item) {
echo (string) $item;
}
foreach ($xml->xpath('//soap:Envelope:ResponseDescription') as $item) {
echo (string) $item;
}
?>