DOM XML関数

  Amazon Raw データ問合せ



view.php
  
<?
$SubscriptionId = '登録ID';

foreach( $_POST as $Key => $Value ) {
	$_POST[$Key] = str_replace("\\\\", "\\", $Value );
	$_POST[$Key] = str_replace("\\'", "'", $_POST[$Key] );
	$_POST[$Key] = str_replace("\\\"", "\"", $_POST[$Key] );
}


if ( $_POST['send'] == 'phpinfo' ) {
	phpinfo();
	exit();
}
if ( $_POST['send'] == 'Direct XML' ) {
	DirectXML();
	exit();
}
if ( $_POST['send'] == 'テキスト表示' ) {
	TextXML();
	exit();
}
if ( $_POST['send'] == 'タグ名指定' ) {
	if ( !extension_loaded( "domxml" ) ) {
		header( "Content-Type: text/html; Charset=shift_jis" );
		print "domxml は使用できません";
		exit();
	}

	$request =
			"http://webservices.amazon.co.jp/onca/xml?" .
			"Service=AWSECommerceService&" .
			"SubscriptionId=$SubscriptionId&" .
			"Operation=ItemLookup&" .
			"ResponseGroup=Large&" .
			"ItemId=" . $_POST['ISBN'];

	$ret = file_get_contents( $request );
	$ret = str_replace(
		$SubscriptionId,
		'MySubscriptionId',
		$ret
	);

	$dom = domxml_open_mem ( $ret );
	$nodes = $dom->get_elements_by_tagname($_POST['TAGNAME']);
	$OutData = PrintNode( $nodes );

}


# **********************************************************
# 取得した XML をそのまま表示 ( text/xml )
# **********************************************************
function DirectXML() {

	global $SubscriptionId;

	header( "Content-Type: text/xml; Charset=utf-8" );

	$request =
			"http://webservices.amazon.co.jp/onca/xml?" .
			"Service=AWSECommerceService&" .
			"SubscriptionId=$SubscriptionId&" .
			"Operation=ItemLookup&" .
			"ResponseGroup=Large&" .
			"ItemId=" . $_POST['ISBN'];

	$ret = file_get_contents ( $request );
	$ret = str_replace(
		$SubscriptionId,
		'MySubscriptionId',
		$ret
	);

	print $ret;

}

# **********************************************************
# 取得した XML テキストとして表示
# **********************************************************
function TextXML() {

	global $SubscriptionId;

	header( "Content-Type: text/html; Charset=utf-8" );

	$request =
			"http://webservices.amazon.co.jp/onca/xml?" .
			"Service=AWSECommerceService&" .
			"SubscriptionId=$SubscriptionId&" .
			"Operation=ItemLookup&" .
			"ResponseGroup=Large&" .
			"ItemId=" . $_POST['ISBN'];

	$ret = file_get_contents ( $request );
	$ret = str_replace(
		$SubscriptionId,
		'MySubscriptionId',
		$ret
	);

	$ret = str_replace( ">", ">\n", $ret );
	$ret = htmlentities( $ret, ENT_NOQUOTES, "utf-8" );

	print "<pre>";
	print $ret;
	print "</pre>";

}

# **********************************************************
# ノ−ドリスト内のデータ取得
# **********************************************************
function PrintNode( $NodeArray ) {

	$ret = "";

	for( $i = 0; $i < count( $NodeArray ); $i++ ) {

		if ( $NodeArray[$i]->has_child_nodes() ) {
			$ret .= PrintNode( $NodeArray[$i]->child_nodes() );
		}
		else {
			$nodeWork = $NodeArray[$i]->parent_node();
			$ret .= $nodeWork->node_name() . "|";
			$ret .= $nodeWork->node_type() . "|";
			$ret .= $NodeArray[$i]->node_name() . "|";
			$ret .= $NodeArray[$i]->node_type() . "|";

			if ( $nodeWork->has_attributes() ) {
				$AttArray = $nodeWork->attributes();
				$ret .= "(";
				for( $j = 0; $j < count( $AttArray ); $j++ ) {
					if ( $j != 0 ) {
						$ret .= "|";
					}
					$ret .= $AttArray[$j]->name();
					$ret .= "|";
					$ret .= $AttArray[$j]->value();
				}
				$ret .= ")";
			}

			$ret .= $NodeArray[$i]->get_content() . "<br>";
		}

	}

	return $ret;

}

?>
<HTML>
<HEAD>
<META http-equiv="Content-type" content="text/html; charset=utf-8">
</HEAD>
<BODY>
<?= $OutData ?>
</BODY>
</HTML>
  

entry.htm
  
<HTML>
<HEAD>
<META http-equiv="Content-type" content="text/html; charset=Shift_JIS">
<STYLE>
	BODY {
		background-color:white
		font-family:Verdana,'MS Pゴシック';
		font-size:13;
	}
</STYLE>
</HEAD>
<BODY>

<FORM
	name=frmMain
	method=POST
	action=view.php
	target=BodyFrame
>

ISBN
<INPUT
	type=text
	name=ISBN
>
&nbsp;
<INPUT
	type=submit
	name=send
	value="Direct XML"
>
&nbsp;
<INPUT
	type=submit
	name=send
	value="テキスト表示"
>
&nbsp;
タグ名
<INPUT
	type=text
	name=TAGNAME
>
&nbsp;
<INPUT
	type=submit
	name=send
	value="タグ名指定"
>
&nbsp;
&nbsp;
<INPUT
	type=submit
	name=send
	value="phpinfo"
>
</FORM>
</BODY>
</HTML>
  

frame.htm
  
<HTML>
<HEAD>
<TITLE>Amazon Raw データ問合せ</TITLE>
<META http-equiv="Content-type" content="text/html; charset=Shift_JIS">
</HEAD>
<FRAMESET id="TopFrame" rows="70,*">
	<FRAME name="HeadFrame" src="entry.htm">
	<FRAME name="BodyFrame">
</FRAMESET>
</HTML>
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ