JMSSerializerBundle
JMSSerializerBundle copied to clipboard
DTD/XSD Schema Generation and Validation
This was a requested feature on Symfony Live, using the Metadata from JMS it is possible to create an XSD Schema.
Also It would be great to provide a way to validate againt an XSD schema during the deserialization process from XML.
I hope you suggested him to send a pull request :)
How would you handle enumerated values?
Duplicating something like a class of nothing but constants in an annotation seems like it could be a maintenance problem.
How would you handle optional values? How would you handle structural depth?
Its not that I don't like the idea, in-fact it has actually piqued my interest. But, in the interest of flexibility, it seems like a very complicated problem.
For instance:
/**
*
*/
class GroupRestriction {
const PUBLIC_GROUP = "PUBLIC";
const PRIVATE_GROUP = "PRIVATE";
const MEMBERS_ONLY = "MEMBERS ONLY";
}
namespace MyBundle\Thingies;
use JMS\Serializer\Annotation as Serializer;
use MyBundle\Constants\GroupRestriction;
/**
* @Serializer\Xml\Root("thingy", "prefix:", "http://blah.example.com/ns")
* @Serializer\Xml\Xsd("name", "filepath???")
*/
class Thingy {
/**
* @Serializer\Expose
* @Serializer\SerializedName("groupRestriction")
* @Serializer\Xml\Enumeration("MyBundle\Constants\GroupRestriction")
*/
public $groupRestriction = GroupRestriction::MEMBERS_ONLY;
/**
* @var SubThingy $subThingy
* @Serializer\Expose
* @Serializer\SerializedName("subThing")
* @Serializer\Xml\AllowedType("SubThingy") ???
*/
public $subThingy;
}
namespace MyBundle\Thingies;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\XmlRoot("subThing")
* How does this inherit the document's namespace?
*/
class SubThingy {
/**
* @Serializer\Xml\MinOccurs(0)
* @Serializer\Xml\MaxOccurs(1)
*/
public $myName = "blah";
}
class AnotherSubThingy extends SubThingy {
}
What would happen?
$thingy = new Thingy();
$thingy->subThingy = new AnotherSubThingy();
// Is this any different? Generating this on the fly again and again seems ill-performant.
$xsd = $serializer->serialize($thingy, 'xsd');
// Do I specify the DTD here? The XSD? My xml:ns?
$out = $serializer->serialize($thingy, 'xml', $xsd);
var_dump($out);
hi! If someone is interested, I'm working on a little tool that generates JMS metadata starting from an XSD definition... https://github.com/goetas/xsd2php#serilize--unserialize
Any suggestion will be helpful :)