遵循xml格式
<fraud_report_responses per_page="100" page="2" total_count="19" pages_count="7">
<fraud_report_response>
<arn>74537604221431003881865</arn>
<transaction_date>2014-01-24</transaction_date>
<fraud_type_code>6</fraud_type_code>
<amount>14625</amount>
<currency>USD</currency>
<card_number>554960******5069</card_number>
<card_brand>master</card_brand>
<customer_email>emil@e-comprocessing.net</customer_email>
<customer_phone>3598851248512</customer_phone>
<transaction_type>sale3d</transaction_type>
<original_transaction_unique_id>f9634ec5e7dbe6ca3871974accb875cd</original_transaction_unique_id>
<original_merchant_transaction_id>f9634ec5e7d5cd</original_merchant_transaction_id>
</fraud_report_response>
<fraud_report_response>
<arn>74537604221431003881862</arn>
<transaction_date>2014-01-27</transaction_date>
<fraud_type_code>4</fraud_type_code>
<amount>3456</amount>
<currency>EUR</currency>
<card_number>454360******5008</card_number>
<card_brand>visa</card_brand>
<customer_email>ivan@e-comprocessing.net</customer_email>
<customer_phone>3598851248123</customer_phone>
<transaction_type>sale</transaction_type>
<original_transaction_unique_id>67fbebc172b743a164a3f3af3d010457</original_transaction_unique_id>
<original_merchant_transaction_id>67fbebc172b743a164a3f3af3d010457</original_merchant_transaction_id>
</fraud_report_response>
</fraud_report_responses>
我在doctrine实体中为商店数据创建了实体类 下面是实体类的代码
class Genesisapicall
{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $arn;
/**
* @var string
*/
private $typeCode;
/**
* @var string
*/
private $currency;
/**
* @var int
*/
private $amount;
/**
* @var string
*/
private $cardBrand;
/**
* @var string
*/
private $customerEmail;
/**
* @var string
*/
private $customerPhone;
/**
* @var \DateTime
*/
private $transactionDate;
/**
* @var string
*/
private $transactionType;
/**
* @var string
*/
private $referenceId;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set arn
*
* @param string $arn
*
* @return Genesisapicall
*/
public function setArn($arn)
{
$this->arn = $arn;
return $this;
}
/**
* Get arn
*
* @return string
*/
public function getArn()
{
return $this->arn;
}
/**
* Set typeCode
*
* @param string $typeCode
*
* @return Genesisapicall
*/
public function setTypeCode($typeCode)
{
$this->typeCode = $typeCode;
return $this;
}
/**
* Get typeCode
*
* @return string
*/
public function getTypeCode()
{
return $this->typeCode;
}
/**
* Set currency
*
* @param string $currency
*
* @return Genesisapicall
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
/**
* Get currency
*
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* Set amount
*
* @param integer $amount
*
* @return Genesisapicall
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return int
*/
public function getAmount()
{
return $this->amount;
}
/**
* Set cardBrand
*
* @param string $cardBrand
*
* @return Genesisapicall
*/
public function setCardBrand($cardBrand)
{
$this->cardBrand = $cardBrand;
return $this;
}
/**
* Get cardBrand
*
* @return string
*/
public function getCardBrand()
{
return $this->cardBrand;
}
/**
* Set customerEmail
*
* @param string $customerEmail
*
* @return Genesisapicall
*/
public function setCustomerEmail($customerEmail)
{
$this->customerEmail = $customerEmail;
return $this;
}
/**
* Get customerEmail
*
* @return string
*/
public function getCustomerEmail()
{
return $this->customerEmail;
}
/**
* Set customerPhone
*
* @param string $customerPhone
*
* @return Genesisapicall
*/
public function setCustomerPhone($customerPhone)
{
$this->customerPhone = $customerPhone;
return $this;
}
/**
* Get customerPhone
*
* @return string
*/
public function getCustomerPhone()
{
return $this->customerPhone;
}
/**
* Set transactionDate
*
* @param \DateTime $transactionDate
*
* @return Genesisapicall
*/
public function setTransactionDate($transactionDate)
{
$this->transactionDate = $transactionDate;
return $this;
}
/**
* Get transactionDate
*
* @return \DateTime
*/
public function getTransactionDate()
{
return $this->transactionDate;
}
/**
* Set transactionType
*
* @param string $transactionType
*
* @return Genesisapicall
*/
public function setTransactionType($transactionType)
{
$this->transactionType = $transactionType;
return $this;
}
/**
* Get transactionType
*
* @return string
*/
public function getTransactionType()
{
return $this->transactionType;
}
/**
* Set referenceId
*
* @param string $referenceId
*
* @return Genesisapicall
*/
public function setReferenceId($referenceId)
{
$this->referenceId = $referenceId;
return $this;
}
/**
* Get referenceId
*
* @return string
*/
public function getReferenceId()
{
return $this->referenceId;
}
}
当我尝试反序列化时,我得到以下结果:
$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$person = $serializer->deserialize($data,'GenesisapicallBundle\Entity\Genesisapicall','xml');
var_dump($person);
回复
object(GenesisapicallBundle\Entity\Genesisapicall)#221 (11) { ["id":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["arn":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["typeCode":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["currency":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["amount":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["cardBrand":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["customerEmail":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["customerPhone":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["transactionDate":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["transactionType":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
["referenceId":"GenesisapicallBundle\Entity\Genesisapicall":private]=> NULL
}
所以有1个问题: 1)如何使用多个attrubute或内联XML列表反序列化xml数据?
如何在没有处理程序中的手动反序列化的情况下使其工作?