易趣API GetSellerList,解析XML响应 [英] Ebay api GetSellerList, Parsing response XML

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

问题描述

我使用易趣的交易API来获取这是目前上市销售的股票。我现在用的电话GetSellerList.I时遇到解析XML,我会再插入到他们的网站商店。

I am using the ebay trading api to get a sellers stock which is currently listed. I am using the call GetSellerList.I am having trouble parsing the xml which I would then insert into there website shop.

这是XML请求。
    

This is the xml request.

<GetSellerListRequest xmlns='urn:ebay:apis:eBLBaseComponents'>

<UserID>".$user_id."</UserID>

<DetailLevel>ReturnAll</DetailLevel>
<ErrorLanguage>RFC 3066</ErrorLanguage>
<WarningLevel>Low</WarningLevel>
<Version>".$compat_level."</Version>

<RequesterCredentials>
    <eBayAuthToken>".$auth_token."</eBayAuthToken>
</RequesterCredentials>

<StartTimeFrom>2012-06-12T23:35:27.000Z</StartTimeFrom>
<StartTimeTo>2012-08-30T23:35:27.000Z</StartTimeTo>

<Pagination>
    <EntriesPerPage>200</EntriesPerPage>
</Pagination>

<OutputSelector>ItemArray.Item.Title</OutputSelector>
<OutputSelector>ItemArray.Item.Description</OutputSelector>
<OutputSelector>ItemArray.Item.BuyItNowPrice</OutputSelector>
<OutputSelector>ItemArray.Item.Quantity</OutputSelector>

</GetSellerListRequest>

我不是最好的,使用PHP,我仍然在学习,所以我必须通过W3Schools的和PHP文档看了一下,没发现什么。我一直在使用这个(从易趣TUTS的),试图通过使用的getElementsByTagName获得XML标记的值。

I am not the best with php, I am still learning so i have looked through w3schools and php docs and found nothing. I have been using this (off of ebay tuts) to try and get the values of the xml tags by using getElementsByTagName.

$dom = new DOMDocument();
$dom->loadXML($response);

$titles = $dom->getElementsByTagName('Title')->length > 0 ? $dom->getElementsByTagName('Title')->item(0)->nodeValue : ''; 

现在我希望我将能够使用该再使用的foreach将其插入到数据库创建一个数组但是当我用这个只得到第一个标题标签的值

Now i was hoping that i would be able to create an array with this then use foreach to insert them into the db but when i use this it only gets the value of the first 'Title' tag

我肯定有创建与它标题的所有值的数组的方式。
所有帮助AP preciated。

Im sure there is a way to create an array with all values of 'Title' in it. All help is appreciated.

推荐答案

这会更容易回答,如果你张贴的响应XML(只是相关部分),而不是请求。

This would be easier to answer if you posted the response XML (just the relevant portion) rather than the request.

在code你只抢到的第一个项目 - 特别是这一部分:

The code you have will only grab the first item - specifically this part:

$dom->getElementsByTagName('Title')->item(0)->nodeValue

相反,你会通过所有的标题元素要循环,并提取它们的nodeValue。这是一个起点:

Rather, you'll want to loop through all the Title elements and extract their nodeValue. This is a starting point:

$dom = new DOMDocument();
$dom->loadXML($response);
$title_nodes = $dom->getElementsByTagName('Title');

$titles = array();

foreach ($title_nodes as $node) {
    $titles[] = $node->nodeValue;
}

这篇关于易趣API GetSellerList,解析XML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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