API与XML相关的? [英] API related with XML?

查看:188
本文介绍了API与XML相关的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否正确呢?我仍然困惑与API是如何工作的。我是新手。我已经围绕谷歌找到答案。我跟着教程,并试图对其进行修改。这是基本的。

我想(模式=热)的幻灯片检索产品的形象是出售。我将AP preciate的帮助,如果你能帮助我了解如何API SHLD来完成。

修改
我想拉从数据库中的图像的巅峰车。所以我想列出它在XML。 您看到下面的所有XML是源视图,但不能在网页本身,它是正常的吗?此外,当我试图显示在网页上的图像和图像不会出现。我不知道我哪里错了。

 <产品与GT;
  <价格><![CDATA [695.00000]>< /价格>
 &所述;可见>&下;![CDATA [是]]≥&下; /可见光>
<应税><![CDATA [是]]>< /应税>
<重><![CDATA [0.00]]>< /重量>
<&UPC GT;<![CDATA []]>< / UPC>
<&SKU GT;<![CDATA []]>< / SKU>
<标题><![CDATA [项链]]>< /标题>
< URL><![CDATA [HTTPS://xxxxx/staging/index.php P =产品和放大器;放大器; n = 80]]>< / URL>
<ThumbnailImageUrl><![CDATA[http://www.xxxxxxxxxx.com/staging/images/products/thumbs/100040.jpg]]></ThumbnailImageUrl>
<ImageUrl><![CDATA[http://www.xxxxxxxx.com/staging/images/products/100040.jpg]]></ImageUrl>
&LT;&停产GT;&LT;![CDATA [否]]&GT;&LT; /停产&GT;
&LT;选项&gt; &LT; /选项&gt;
&LT;&添加GT;&LT;![CDATA [2010-05-12十三时五十分00秒]&GT;&LT; /&添加GT;
&LT; ManufaturerName&GT;&LT;![CDATA []]&GT;&LT; / ManufaturerName&GT;
<Description><![CDATA[<p>&nbsp;</p><p>&nbsp;</p>]]></Description>
&LT; AmazonId&GT;&LT;![CDATA []]&GT;&LT; / AmazonId&GT;
&LT; AmazonItemCondition&GT;&LT;![CDATA []]&GT;&LT; / AmazonItemCondition&GT;
&LT; AmazonIdType&GT;&LT;![CDATA []]&GT;&LT; / AmazonIdType&GT;
&LT; EbayCategoryId&GT;&LT;![CDATA []]&GT;&LT; / EbayCategoryId&GT;
&LT; YahooPath&GT;&LT;![CDATA []]&GT;&LT; / YahooPath&GT;
&LT; GoogleItemCondition&GT;&LT;![CDATA []]&GT;&LT; / GoogleItemCondition&GT;
&LT; PricegrabberCategory&GT;&LT;![CDATA []]&GT;&LT; / PricegrabberCategory&GT;
&LT; PricegrabberItemCondition&GT;&LT;![CDATA []]&GT;&LT; / PricegrabberItemCondition&GT;
&LT; PricegrabberPartNumber&GT;&LT;![CDATA []]&GT;&LT; / PricegrabberPartNumber&GT;
&所述;库存控制&GT;&下;![CDATA [是]]≥&下; /库存控制&GT;
&所述; PID&GT;&下;![CDATA [80]]≥&下; / PID&GT;
&所述;产品编号&GT;&下;![CDATA [100040]]≥&下; /产品编号&GT;
&所述; QOH&GT;&下;![CDATA [1]]≥&下; / QOH&GT;
&LT; NextagCategory&GT;&LT;![CDATA []]&GT;&LT; / NextagCategory&GT;
&LT; NextagPartNumber&GT;&LT;![CDATA []]&GT;&LT; / NextagPartNumber&GT;
&LT; NextagItemCondition&GT;&LT;![CDATA []]&GT;&LT; / NextagItemCondition&GT;
&LT; /产品与GT;

我的code

 &LT; PHP
    $店=www.xxx.com /分期/内容/管理/插件/ OpenAPI的/的index.php?';
    $ USER =ASD
    $密码=广告;
    $令牌='令牌';    //组装帐户网址
    $ URL =的https://'.$shop用户名=$用户&放大器;放大器;密码=$密码&放大器;放大器;令牌=$令牌。。。。。 &放大器; apiType = XML和放大器;调用=&的GetProducts放大器;模式=热;    //设置卷曲对象
    $卷曲= curl_init();
    curl_setopt($ l_oCurl,CURLOPT_POST,1);
    curl_setopt($卷曲,CURLOPT_URL,$网址);    $响应= curl_exec($卷曲);
    curl_close($卷曲);
    $ image_xml =新的SimpleXMLElement($响应);
   **的foreach($ XML的&GT; ThumbnailImageUrl为$大拇指){
回声&下; IMG SRC =$大拇指。/&gt;中; **
}    ?&GT;


解决方案

的SimpleXML 可以加载使用simplexml_load_file 远程URL和所有的libxml基地扩展可以用自定义的上下文。只是 stream_context_create ,然后用的 libxml_set_streams_context 。请参见上下文列表和选项

要生成一个URL连接codeD字符串,请使用 http_build_query

至于使用SimpleXML,请参阅href=\"http://us3.php.net/manual/en/simplexml.examples-basic.php\"在PHP rel=\"nofollow\">基本用法示例的。你基本上只需要遍历节点和回声它,例如

 回声$ sxe-&GT; someNode-&GT; someOtherNode-&GT; ThumbnailImageUrl;

Is it done correctly? I am still confused with how api works. I am newbie. I have gone around google to find answers. I followed tutorial and tried to modify it. It is basic one.

I would like to retrieve the images of products which is on sale (mode=hot) for slideshow. I will appreciate the help if you could help me to understand how api shld be done.

EDIT I am trying to pull the images from database in pinnacle cart. so i wanted to list out what it have in xml. All xml you see below is on source view but not on webpage itself, is it normal? Also when I am trying to show the images on webpage and the images don't appear. I am not sure where I went wrong.

     <Product>
  <Price><![CDATA[695.00000]]></Price>
 <Visible><![CDATA[Yes]]></Visible>
<Taxable><![CDATA[Yes]]></Taxable>
<Weight><![CDATA[0.00]]></Weight>
<UPC><![CDATA[]]></UPC>
<Sku><![CDATA[]]></Sku>
<Title><![CDATA[Necklace]]></Title>
<URL><![CDATA[https://xxxxx/staging/index.php?p=product&amp;id=80]]></URL>
<ThumbnailImageUrl><![CDATA[http://www.xxxxxxxxxx.com/staging/images/products/thumbs/100040.jpg]]></ThumbnailImageUrl>
<ImageUrl><![CDATA[http://www.xxxxxxxx.com/staging/images/products/100040.jpg]]></ImageUrl>
<Discontinued><![CDATA[No]]></Discontinued>
<Options>    </Options>
<Added><![CDATA[2010-05-12 13:50:00]]></Added>
<ManufaturerName><![CDATA[]]></ManufaturerName>
<Description><![CDATA[<p>&nbsp;</p><p>&nbsp;</p>]]></Description>
<AmazonId><![CDATA[]]></AmazonId>
<AmazonItemCondition><![CDATA[]]></AmazonItemCondition>
<AmazonIdType><![CDATA[]]></AmazonIdType>
<EbayCategoryId><![CDATA[]]></EbayCategoryId>
<YahooPath><![CDATA[]]></YahooPath>
<GoogleItemCondition><![CDATA[]]></GoogleItemCondition>
<PricegrabberCategory><![CDATA[]]></PricegrabberCategory>
<PricegrabberItemCondition><![CDATA[]]></PricegrabberItemCondition>
<PricegrabberPartNumber><![CDATA[]]></PricegrabberPartNumber>
<InventoryControl><![CDATA[Yes]]></InventoryControl>
<PID><![CDATA[80]]></PID>
<ProductId><![CDATA[100040]]></ProductId>
<Qoh><![CDATA[1]]></Qoh>
<NextagCategory><![CDATA[]]></NextagCategory>
<NextagPartNumber><![CDATA[]]></NextagPartNumber>
<NextagItemCondition><![CDATA[]]></NextagItemCondition>
</Product>

My code

    <?php
    $shop='www.xxx.com/staging/content/admin/plugins/openapi/index.php?';
    $user = "asd";
    $password = "ad";
    $token = 'token';

    // Assemble the account url
    $url = 'https://'.$shop."username=".$user."&amp;password=".$password."&amp;token=".$token. "&apiType=xml&call=GetProducts&mode=hot";

    // Setup the cURL object
    $curl = curl_init();
    curl_setopt($l_oCurl, CURLOPT_POST, 1);
    curl_setopt( $curl, CURLOPT_URL, $url );

    $response=curl_exec($curl);
    curl_close($curl);
    $image_xml = new SimpleXMLElement($response);
   **foreach($xml->ThumbnailImageUrl as $thumbs){
echo "<img src=".$thumbs."/>";**
}

    ?>

解决方案

SimpleXml can load remote URLs with simplexml_load_file and all libxml bases extensions can be used with a custom Stream Context. Just create your custom context with stream_context_create and then set it with libxml_set_streams_context. See Context List and Options

To generate a URL encoded string, use http_build_query

As for using SimpleXml, please see the Basic Usage Examples in the PHP Manual. You basically just have to traverse to the node and echo it, e.g.

echo $sxe->someNode->someOtherNode->ThumbnailImageUrl;

这篇关于API与XML相关的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆