2017-10-04 142 views
2

我試圖反序列化這個XMLJMS反序列化與XML列表,的XPath的SimpleXMLElement不工作

<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <InformationDisclosureResponse xmlns="http://ASD.pl"> 
     <DisclosureReport> 
      <Number>U/123</Number> 
      <Created>2017-10-03T15:00:50+02:00</Created> 
      <SearchCriterion> 
       <NonConsumerIdentityNumber> 
        <TaxId>123123123</TaxId> 
       </NonConsumerIdentityNumber> 
       <AuthorizationDateSpecified>false</AuthorizationDateSpecified> 
       <ActAuthorizationDateSpecified>false</ActAuthorizationDateSpecified> 
       <SearchType>RegularSearch</SearchType> 
       <SearchCriterionType>TaxId</SearchCriterionType> 
      </SearchCriterion> 
      <Requester> 
       <LegalPerson> 
        <Name>Test</Name> 
        <IdentityNumber> 
         <TaxId>123123123</TaxId> 
        </IdentityNumber> 
        <SeatAddress> 
         <Line>asd 72</Line> 
        </SeatAddress> 
       </LegalPerson> 
       <LoginFullName>ASD</LoginFullName> 
      </Requester> 
      <Summary> 
       <InformationCount>2</InformationCount> 
       <TotalArrears> 
        <Amount>123321.52</Amount> 
        <Currency>PLN</Currency> 
       </TotalArrears> 
      </Summary> 
      <PositiveInformationSummary> 
       <ProvidersCount>0</ProvidersCount> 
      </PositiveInformationSummary> 
      <Report> 
       <ObligationInformations> 
        <ObligationInformation category="0"> 
         <Debtor> 
          <Entrepreneur> 
           <Name>ASDASD</Name> 
           <AddressForMail> 
            <Line>ASD ASD</Line> 
           </AddressForMail> 
           <SeatAddress> 
            <Line>ASD123</Line> 
           </SeatAddress> 
           <NonConsumerIdentityNumber> 
            <TaxId>123123123</TaxId> 
           </NonConsumerIdentityNumber> 
           <FirstName>ASD</FirstName> 
           <Surname>ASD</Surname> 
          </Entrepreneur> 
         </Debtor> 
         <Provider> 
          <LegalPerson> 
           <Name>ASD</Name> 
           <IdentityNumber> 
            <TaxId>123123123</TaxId> 
           </IdentityNumber> 
           <SeatAddress> 
            <Line>Asd, asd</Line> 
           </SeatAddress> 
           <RegistrationNumber>123123</RegistrationNumber> 
           <RegistryName>ASD</RegistryName> 
           <Regon>123123</Regon> 
           <Ekd>123S/07</Ekd> 
          </LegalPerson> 
         </Provider> 
         <Title>Fd-dasd</Title> 
         <Type>Invoice</Type> 
         <PaymentDate>2017-04-20T00:00:00+02:00</PaymentDate> 
         <NoObjections>true</NoObjections> 
         <CallSent>2017-05-29T00:00:00+02:00</CallSent> 
         <Debt> 
          <Amount>123.80</Amount> 
          <Currency>PLN</Currency> 
         </Debt> 
         <Arrears> 
          <Amount>321.80</Amount> 
          <Currency>PLN</Currency> 
         </Arrears> 
        </ObligationInformation> 
       </ObligationInformations> 
      </Report> 
     </DisclosureReport> 
    </InformationDisclosureResponse> 
</s:Body> 

帶班

class ReportResponse{ 
/** 
* @var DisclosureReport 
* 
* @JMS\Type("DisclosureReport") 
* @JMS\SerializedName("DisclosureReport") 
*/ 
public $disclosureReport; 
//geter 
} 

class DisclosureReport{ 
/** 
* @var string|null 
* 
* @JMS\Type("string") 
* @JMS\SerializedName("Number") 
*/ 
public $number; 

/** 
* @var string|null 
* 
* @JMS\Type("string") 
* @JMS\SerializedName("Created") 
*/ 
public $created; 

/** 
* @var SearchCriterion|null 
* 
* @JMS\Type("SearchCriterion") 
* @JMS\SerializedName("SearchCriterion") 
*/ 
public $searchCriterion; 

/** 
* @var Requester|null 
* 
* @JMS\Type("Requester") 
* @JMS\SerializedName("Requester") 
*/ 
public $requester; 

/** 
* @var Summary|null 
* 
* @JMS\Type("Summary") 
* @JMS\SerializedName("Summary") 
*/ 
public $summary; 

/** 
* @var PositiveInformationSummary|null 
* 
* @JMS\Type("PositiveInformationSummary") 
* @JMS\SerializedName("PositiveInformationSummary") 
*/ 
public $positiveInformationSummary; 

/** 
* @var Report|null 
* 
* @JMS\Type("Report") 
* @JMS\SerializedName("Report") 
*/ 
public $report; 
//geters 
} 

class Report{ 
/** 
* @var ArrayCollection|null 
* 
* @JMS\Type("ArrayCollection<ObligationInformation>") 
* @JMS\SerializedName("ObligationInformations") 
* @JMS\XmlList(entry="ObligationInformation") 
*/ 
public $obligationInformations; 

/** 
* @var ArrayCollection|null 
* 
* @JMS\Type("ArrayCollection<PaidObligationInformation>") 
* @JMS\SerializedName("PaidObligationInformations") 
* @JMS\XmlList(entry="PaidObligationInformation") 
*/ 
public $paidObligationInformations; 
} 

解析的每一件事情都可以,但是帶有ObligationInformation的ArrayCollection不會。即使使用array類型,仍然獲得空ArrayCollection。

嘗試不使用屬性類別,使用JMS/Serializer-bundle(當前我使用1.1.0,使用jms/serializer 1.5.0)的不同版本,但沒有成功。

調試時我發現這裏有https://github.com/schmittjoh/serializer/blob/1.5.0/src/JMS/Serializer/XmlDeserializationVisitor.php#L158我得到空數組。 $entityNameObligationInformation,像這裏http://sandbox.onlinephpfunctions.com/code/9f6213c5937f8e1cc78e46c710ae1a0f009338d5在沙箱PHP中,但在這裏我得到的數據。

什麼時候在我的應用程序的沙箱中做什麼,結果與沙箱中的相同。但是在這個帶有$data這個JMS文件的沙盒$xml中,我得到空數組爲什麼?

回答

1

你的問題是你有錯誤的XML名稱空間定義在<InformationDisclosureResponse xmlns="http://ASD.pl"> 元素。嘗試沒有它的反序列化,它應該做的伎倆。

+0

此命名空間故意改變,但我忘了在課堂上改變它。我使用正確的命名空間,所以它沒有解決我問題Siadul。 –

0

我發現這個問題的臨時解決方案。

在JMS標籤XmlList定義enrty爲child::*現在它看起來像:

@JMS\XmlList(entry="child::*") 

和它的作品!但它的工作..但仍然..