<i id='Tpc2H'><tr id='Tpc2H'><dt id='Tpc2H'><q id='Tpc2H'><span id='Tpc2H'><b id='Tpc2H'><form id='Tpc2H'><ins id='Tpc2H'></ins><ul id='Tpc2H'></ul><sub id='Tpc2H'></sub></form><legend id='Tpc2H'></legend><bdo id='Tpc2H'><pre id='Tpc2H'><center id='Tpc2H'></center></pre></bdo></b><th id='Tpc2H'></th></span></q></dt></tr></i><div id='Tpc2H'><tfoot id='Tpc2H'></tfoot><dl id='Tpc2H'><fieldset id='Tpc2H'></fieldset></dl></div>

      <bdo id='Tpc2H'></bdo><ul id='Tpc2H'></ul>

    <legend id='Tpc2H'><style id='Tpc2H'><dir id='Tpc2H'><q id='Tpc2H'></q></dir></style></legend>

    <small id='Tpc2H'></small><noframes id='Tpc2H'>

  1. <tfoot id='Tpc2H'></tfoot>

      解析亚马逊 MWS Scratchpad 响应

      Parsing Amazon MWS Scratchpad response(解析亚马逊 MWS Scratchpad 响应)
      1. <small id='TGJ7M'></small><noframes id='TGJ7M'>

          • <bdo id='TGJ7M'></bdo><ul id='TGJ7M'></ul>
            <tfoot id='TGJ7M'></tfoot>
              <i id='TGJ7M'><tr id='TGJ7M'><dt id='TGJ7M'><q id='TGJ7M'><span id='TGJ7M'><b id='TGJ7M'><form id='TGJ7M'><ins id='TGJ7M'></ins><ul id='TGJ7M'></ul><sub id='TGJ7M'></sub></form><legend id='TGJ7M'></legend><bdo id='TGJ7M'><pre id='TGJ7M'><center id='TGJ7M'></center></pre></bdo></b><th id='TGJ7M'></th></span></q></dt></tr></i><div id='TGJ7M'><tfoot id='TGJ7M'></tfoot><dl id='TGJ7M'><fieldset id='TGJ7M'></fieldset></dl></div>
                <tbody id='TGJ7M'></tbody>
              <legend id='TGJ7M'><style id='TGJ7M'><dir id='TGJ7M'><q id='TGJ7M'></q></dir></style></legend>
                本文介绍了解析亚马逊 MWS Scratchpad 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试解析来自亚马逊的 xml 文件,但遇到了困难.我正在使用 simplexml_load_string

                I am trying to parse xml file from amazon but found difficulties. I am using simplexml_load_string

                $xml = simplexml_load_string('我的xml在这里');

                $xml = simplexml_load_string( 'My xml here' );

                但是当我这样做时

                echo $xml->GetMatchingProductResult->Product->AttributeSets;

                echo $xml->GetMatchingProductResult->Product->AttributeSets;

                什么都不显示

                如何获取品牌价值?

                我的 xml 文件:

                <?xml version="1.0"?>
                <GetMatchingProductResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
                <GetMatchingProductResult ASIN="B003IOSNNQ" status="Success">
                  <Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
                    <Identifiers>
                      <MarketplaceASIN>
                        <MarketplaceId>A1F83G8C2ARO7P</MarketplaceId>
                        <ASIN>B003IOSNNQ</ASIN>
                      </MarketplaceASIN>
                    </Identifiers>
                    <AttributeSets>
                      <ns2:ItemAttributes xml:lang="en-GB">
                        <ns2:Binding>Misc.</ns2:Binding>
                        <ns2:Brand>eSecure</ns2:Brand>
                        <ns2:Feature>Colour: Classic Black</ns2:Feature>
                        <ns2:Feature>Thickness: Approximately 40mm - More than msot sellers</ns2:Feature>
                        <ns2:Feature>Dimensions [length x width at widest and narrowest]: approximately 280 x 190 x 70mm</ns2:Feature>
                        <ns2:Feature>Material: Stretch Lycra, Silica Gel</ns2:Feature>
                        <ns2:Feature>Ideal for Standard Bicycle / Static Exercise Bike</ns2:Feature>
                        <ns2:Label>eSecure</ns2:Label>
                        <ns2:Manufacturer>eSecure</ns2:Manufacturer>
                        <ns2:PackageDimensions>
                          <ns2:Height Units="inches">2.13</ns2:Height>
                          <ns2:Length Units="inches">10.71</ns2:Length>
                          <ns2:Width Units="inches">7.72</ns2:Width>
                          <ns2:Weight Units="pounds">0.49</ns2:Weight>
                        </ns2:PackageDimensions>
                        <ns2:PackageQuantity>1</ns2:PackageQuantity>
                        <ns2:ProductGroup>Sports</ns2:ProductGroup>
                        <ns2:ProductTypeName>SPORTING_GOODS</ns2:ProductTypeName>
                        <ns2:Publisher>eSecure</ns2:Publisher>
                        <ns2:SmallImage>
                          <ns2:URL>http://ecx.images-amazon.com/images/I/41OIjmpza2L._SL75_.jpg</ns2:URL>
                          <ns2:Height Units="pixels">75</ns2:Height>
                          <ns2:Width Units="pixels">75</ns2:Width>
                        </ns2:SmallImage>
                        <ns2:Studio>eSecure</ns2:Studio>
                        <ns2:Title>eSecure - Extra Comfort Bike Bicycle Gel Saddle Seat Cover</ns2:Title>
                      </ns2:ItemAttributes>
                    </AttributeSets>
                    <Relationships/>
                    <SalesRankings>
                      <SalesRank>
                        <ProductCategoryId>sports_display_on_website</ProductCategoryId>
                        <Rank>398</Rank>
                      </SalesRank>
                      <SalesRank>
                        <ProductCategoryId>458338031</ProductCategoryId>
                        <Rank>1</Rank>
                      </SalesRank>
                    </SalesRankings>
                  </Product>
                </GetMatchingProductResult>
                <ResponseMetadata>
                  <RequestId>9b44aba6-d1fa-486a-8114-2bc4f9311d8d</RequestId>
                </ResponseMetadata>
                </GetMatchingProductResponse>
                

                推荐答案

                我知道这是一个老问题,但我遇到了同样的问题.

                I know this is an old question but I had a hard time with the same thing.

                首先 simplexml_load_string 不会像这样处理抛出的命名空间,因此您可以递归检查然后加载命名空间,评估 xml 并浪费大量时间...

                First simplexml_load_string doesn't handle the namespaces thrown in like this, so you could go recursively and check and then load the namespaces, evaluate the xml and waste a lot of time ...

                就我而言,我并不关心使用命名空间评估 xml 的格式,所以我只是使用正则表达式将它们从字符串中删除.在这个 simplexml_load_string 之后不会再省略这些部分,并且使用 json_encode 和 json_decode 很容易从中得到一个数组.

                In my case I didn't care about evaluating the format of the xml with the namespaces, so I just removed them from the string with regex. After this simplexml_load_string won't omit those parts anymore and it's easy to get an array out of it with json_encode and json_decode.

                //convert an xml string into an array
                function xml2array($xml){
                    $xml = preg_replace('/(</?)w+:([^>]*>)/', '$1$2', $xml); //get rid of namespaces
                    $xml = simplexml_load_string($xml);
                    return json_decode(json_encode($xml),true); //use built-in stuff
                }
                

                唯一的问题是当 xml 充满了包含有用数据的属性时,那么您将需要其他东西而不是 simplexml_load_string.请注意,它会从这里返回一个 @attributes 元素:

                The only problem with this is when the xml is full of attributes containing useful data, then you would need something else instead of simplexml_load_string. Note that it returns an @attributes element from this:

                <GetMatchingProductResult ASIN="B003IOSNNQ" status="Success">
                

                但从这部分省略:

                <Width Units="pixels">75</Width>
                

                我不知道它为什么会检查嵌套标签或检查嵌套标签的深度.

                I have no idea why or how deep down it would check in the nested tags.

                这篇关于解析亚马逊 MWS Scratchpad 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <bdo id='kf7IQ'></bdo><ul id='kf7IQ'></ul>

                      • <legend id='kf7IQ'><style id='kf7IQ'><dir id='kf7IQ'><q id='kf7IQ'></q></dir></style></legend>
                        <i id='kf7IQ'><tr id='kf7IQ'><dt id='kf7IQ'><q id='kf7IQ'><span id='kf7IQ'><b id='kf7IQ'><form id='kf7IQ'><ins id='kf7IQ'></ins><ul id='kf7IQ'></ul><sub id='kf7IQ'></sub></form><legend id='kf7IQ'></legend><bdo id='kf7IQ'><pre id='kf7IQ'><center id='kf7IQ'></center></pre></bdo></b><th id='kf7IQ'></th></span></q></dt></tr></i><div id='kf7IQ'><tfoot id='kf7IQ'></tfoot><dl id='kf7IQ'><fieldset id='kf7IQ'></fieldset></dl></div>

                          <tbody id='kf7IQ'></tbody>
                      • <small id='kf7IQ'></small><noframes id='kf7IQ'>

                          <tfoot id='kf7IQ'></tfoot>