【发布时间】:2016-07-03 13:01:30
【问题描述】:
我目前正在做一个酒店预订网站。所以我有一个使用内容管理系统 Magento 制作的网站。我想将它与 XML API 集成。他们为我提供了完整的手动集成内容。但没有解释如何执行此操作。它包含 Web 方法及其 XML。但我不明白将这些代码放在哪里以及如何放置。 我刚刚google了一下,发现堆栈溢出:
"note.xml"
<currencies>
<currency name="US dollar" code_alpha="USD" code_numeric="840" />
<currency name="Euro" code_alpha="EUR" code_numeric="978" />
</currencies>
solution
Using DomDocument
<?php
$str = <<<XML
<currencies>
<currency name="US dollar" code_alpha="USD" code_numeric="840" />
<currency name="Euro" code_alpha="EUR" code_numeric="978" />
</currencies>
XML;
$dom = new DOMDocument();
$dom->loadXML($str);
foreach($dom->getElementsByTagName('currency') as $currency)
{
echo $currency->getAttribute('name'), "\n";
echo $currency->getAttribute('code_alpha'), "\n";
echo $currency->getAttribute('code_numeric'), "\n";
echo "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+\n";
}
?>
Using simplexml:
<?php
$str = <<<XML
<currencies>
<currency name="US dollar" code_alpha="USD" code_numeric="840" />
<currency name="Euro" code_alpha="EUR" code_numeric="978" />
</currencies>
XML;
$currencies = new SimpleXMLElement($str);
foreach($currencies as $currency)
{
echo $currency['name'], "\n";
echo $currency['code_alpha'], "\n";
echo $currency['code_numeric'], "\n";
echo "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+\n";
}
?>
但我不明白在哪里以及如何编写这个。执行此操作的过程。 有人可以为我提供执行此操作的链接或互联网上可用的任何详细说明。 我该怎么做? 什么是技术相关的东西(编码),我应该知道这样做吗?
【问题讨论】:
-
我可以为您指明与 Magento 的原生 API 集成的正确方向,但您能否告诉我您尝试使用上述代码实现的具体结果/结果?
-
以上代码只是我从堆栈溢出中获得的关于如何将代码从 xml 文档转换为 php 或任何其他代码的示例代码(不确定)。因此,如果我有一个 xml 文档和一个 magento 网站,我只想知道如何进行 xml api 集成(逐步详细信息)。任何提供详细信息的网站链接也将是可观的。提前致谢。