将xml“拉取”到API的正确方法


Correct way to " pull " xml into API?

将xml拉入API的正确方法是什么?

API 代码中的直接 xml 示例;(这是我们不想要的,我们需要它从文件中提取 xml)

BigCommerce_Api::useXml();
$xml = "<?xml version="1.0" encoding="UTF-8"?>
    <brand>
        <name>Apple</name>
        <search_keywords>computers laptops</search_keywords>
    </brand>";
$result = BigCommerce_Api::createBrand($xml);

我狡猾地尝试通过 fopen 引入 xml;

<?
require_once 'BigCommerce/Api.php';
BigCommerce_Api::configure(array(
'store_url' => 'https://apiurl',
'username'  => 'admin',
'api_key'   => 'apitoken'
));
$filename = "xmlfile.xml";
$handle = fopen($filename, "r");
$XPost = fread($handle, filesize($filename));
fclose($handle);
BigCommerce_Api::useXml();
$xml = $XPost;
$result = BigCommerce_Api::createProduct($xml); 
?>

如果有人可以让我们知道如何将xml适当地引入useXML变量,请随时分享:)

(代码的某些格式是在应用引号后支付的)

谢谢!

我不知道

你为什么让你的生活变得如此复杂:

BigCommerce_Api::useXml();
$xml = file_get_contents('xmlfile.xml');
$result = BigCommerce_Api::createBrand($xml);

请参阅file_get_contents