2016-08-07 7 views
0

저는 프로젝트에서 작업 중이며 벽돌 벽을 실행했습니다. 나는 웹을 연구했고 아무도 나와 같은 문제를 안고있는 것 같고 화가났다. 나는 반환의 전체 xml을 simplexml_load_string()에서 얻을 수 없습니다. 내가 simplexml을 사용하면 문제가 생깁니다. :은 대부분이 문제가 있다고 생각하는 곳입니다. 하단 예제에서 판매 순위 태그를보고 계층 구조를 보면 네임 스페이스가 하나도 없음을 알 수 있습니다.simplexml로 데이터를 수정하는 방법

<GetMatchingProductForIdResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"> 
<GetMatchingProductForIdResult Id="883028968343" IdType="UPC" status="Success"> 
    <Products xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd"> 
     <Product> 
      <Identifiers> 
       <MarketplaceASIN> 
        <MarketplaceId>ATVPDKIKX0DER</MarketplaceId> 
        <ASIN>B007C435CW</ASIN></MarketplaceASIN> 
      </Identifiers> 
      <AttributeSets> 
       <ns2:ItemAttributes xml:lang="en-US"> 
       <ns2:Binding>Apparel</ns2:Binding> 
       <ns2:Brand>Secret Wishes</ns2:Brand> 
       <ns2:Color>Black</ns2:Color> 
       <ns2:Department>womens</ns2:Department> 
       <ns2:Feature>Black and gold musketeer or pirate costume</ns2:Feature> 
       <ns2:Feature>Features strapless corset with lace up back and matching mini skirt</ns2:Feature> 
       <ns2:Feature>Hat and choker included</ns2:Feature> 
       <ns2:Feature>Boots and sword available separately</ns2:Feature> 
       <ns2:Feature>Sexy wishes for playful adults is a division of rubies costume company</ns2:Feature> 
       <ns2:Genre>Historical</ns2:Genre> 
       <ns2:IsAdultProduct>false</ns2:IsAdultProduct> 
       <ns2:Label>Secret Wishes</ns2:Label> 
       <ns2:Manufacturer>Secret Wishes</ns2:Manufacturer><ns2:Model>889683XS</ns2:Model> 
       <ns2:PackageDimensions> 
        <ns2:Height Units="inches">1.10</ns2:Height> 
        <ns2:Length Units="inches">14.50</ns2:Length> 
        <ns2:Width Units="inches">11.40</ns2:Width> 
        <ns2:Weight Units="pounds">0.90</ns2:Weight> 
       </ns2:PackageDimensions> 
       <ns2:ProductGroup>Apparel</ns2:ProductGroup> 
       <ns2:ProductTypeName>ADULT_COSTUME</ns2:ProductTypeName>  
       <ns2:Publisher>Secret Wishes</ns2:Publisher> 
       <ns2:Size>X-Small</ns2:Size> 
       <ns2:SmallImage> 
        <ns2:URL>http://ecx.images-amazon.com/images/I/41YPo629q4L._SL75_.jpg</ns2:URL> 
        <ns2:Height Units="pixels">75</ns2:Height> 
        <ns2:Width Units="pixels">37</ns2:Width> 
       </ns2:SmallImage> 
      </AttributeSets> 
      <SalesRankings> 
       <SalesRank> 
        <ProductCategoryId>office_product_display_on_website</ProductCategoryId> 
        <Rank>259</Rank> 
       </SalesRank> 
      </SalesRankings> 

      ECT... 

내가 print_r(simplexml_load_string(curl_exec($ch);을 할 때 얻을 응답은 이것이다 :

SimpleXMLElement Object 
(
[GetMatchingProductForIdResult] => SimpleXMLElement Object 
    (
     [@attributes] => Array 
      (
       [Id] => 883028968343 
       [IdType] => UPC 
       [status] => Success 
      ) 

     [Products] => SimpleXMLElement Object 
      (
       [Product] => SimpleXMLElement Object 
        (
         [Identifiers] => SimpleXMLElement Object 
          (
           [MarketplaceASIN] => SimpleXMLElement Object 
            (
             [MarketplaceId] => ATVPDKIKX0DER 
             [ASIN] => B007C435CW 
            ) 

          ) 

         [AttributeSets] => SimpleXMLElement Object 
          (
          ) 

         [Relationships] => SimpleXMLElement Object 
          (
           [VariationParent] => SimpleXMLElement Object 
            (
             [Identifiers] => SimpleXMLElement Object 
              (
               [MarketplaceASIN] => SimpleXMLElement Object 
                (
                 [MarketplaceId] => ATVPDKIKX0DER 
                 [ASIN] => B00B7DAJAA 
                ) 

              ) 

            ) 

          ) 

         [SalesRankings] => SimpleXMLElement Object 
          (
          ) 

        ) 

      ) 

    ) 

내가 가능한 문제가 무엇인지 이해가 안 돼요 여기에 원래의 XML입니다. 이 데이터의 주요 목표는 JSON으로 푸시하는 것입니다. 누군가 나를 도울 수 있다면 크게 감사하겠습니다. 감사!

+0

[단순 XML - 노드의 콜론 처리] 가능한 복제본 (http://stackoverflow.com/questions/1186107/simple-xml-dealing-with-colons-in-nodes) – ThW

+0

나는 당신을 찾고 있지 않습니다. 콜론 노드를 다루는 방법을 알려줘. 심지어 판매 순위가 보이지 않습니다. – McStuffins

+1

콜론은 로컬 노드 이름에서 네임 스페이스 접두어를 구분합니다. 노드에 네임 스페이스가 있습니다. 네임 스페이스를 사용하여 XML을 읽는 방법을 배워야합니다. 캐릭터를 교체하는 것은 몇 가지 방법으로 손상됩니다. 첫 번째 네임 스페이스 접두사는 실제 네임 스페이스가 아닙니다. 변경할 수 있으며 선택 사항입니다. 두 번째 문자는 파일의 다른 부분에서 정기적으로 발생할 수 있습니다. – ThW

답변

-1

태그 이름에 ':'기호가 있기 때문에 simplexml이 올바르게 작동하지 않는 것처럼 보입니다. 로 : '': 당신은 모두를 대체 할 수

$xml = str_replace (':', '_', $xml); 

또는 here 설명 다른 솔루션을 찾습니다.

+0

왜 이렇게하면 판매 순위가 표시되지 않습니까? – McStuffins

+0

curl_exec에서 XML 파일을 완전히로드했는지 확인 했습니까? – stweb

+0

그리고 그렇다면이 [질문] (http://stackoverflow.com/questions/15553519/parsing-amazon-mws-scratchpad-response)을 찾아보십시오. 구문 분석하기 전에 xml을 변환하는 코드가 있습니다. – stweb

관련 문제