[英]PHP XML serializer
Is there some php libraries which implement serialization of data to XML-format like serialize()
and unserialize()
(with restoring objects from XML) functions of objects with private
and protected
fields?是否有一些 php 库将数据序列化为 XML 格式,如具有
private
和protected
字段的对象的serialize()
和unserialize()
(从 XML 恢复对象)函数?
PEAR XML_Serializer works fine with type hints option, but it doen't deal with protected fields. PEAR XML_Serializer 与类型提示选项一起工作正常,但它不处理受保护的字段。
The Symfony Serializer Component provides serialize()
and deserialize()
methods and supports multiple formats out of the box: XML, JSON, YAML... Symfony Serializer 组件提供了
serialize()
和deserialize()
方法并支持多种开箱即用的格式:XML、JSON、YAML...
It is included with Symfony but you can use it even in a non Symfony project , by installing it with composer:它包含在 Symfony 中,但您甚至可以在非 Symfony 项目中使用它,通过使用 composer 安装它:
composer require symfony/serializer
If you use the ObjectNormalizer
as shown in the documentation example , don't forget to also install symfony/property-access
.如果您使用文档示例中所示的
ObjectNormalizer
,请不要忘记同时安装symfony/property-access
。
Hoping this is not considered spamming, but I've been working on a library that deals with serializing and deserialing objects from and to XML.希望这不会被视为垃圾邮件,但我一直在研究一个库,该库处理从 XML 到 XML 的序列化和反序列化对象。
https://github.com/evert/sabre-xml/ https://github.com/evert/sabre-xml/
However, it doesn't do exactly what you're asking.但是,它并不完全符合您的要求。 Every object you want to serialize needs to implement a
serializeXML
and deserializeXML
method.要序列化的每个对象都需要实现
serializeXML
和deserializeXML
方法。 In this method you can decide exactly what you need to implement.在这种方法中,您可以准确决定需要实施的内容。
If you do plan to use this, I would actually be happy to include the exact feature you want as a PHP 5.4 trait.如果您确实打算使用它,我实际上很乐意将您想要的确切功能作为 PHP 5.4 特性包含在内。 Just send me a message (you can find my info on github).
给我发个消息(你可以在github上找到我的信息)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.