Answer the question
In order to leave comments, you need to log in
How to generate object from XML?
Is there a library that allows you to do this? I looked at jsm/serializer but it's a bit different.
For example, there are interfaces
interface Form{
public function addElement(Element $element);
}
interface Element{
}
interface Text extends Element{
public function setName($name);
}
interface Button extends Element{
public function setLabel($label);
}
<form>
<text name="tf1"/>
<button label="Do it!"/>
</form>
$form = new Form();
$t = new Text();
$t->setName('tf1');
$form->addElement($t);
$t = new Button();
$t->setLabel('Do it!');
$form->addElement($t);
Answer the question
In order to leave comments, you need to log in
We implemented such a thing with a separate form factory. Through SimpleXML it's not difficult.
Do you have zf2? If you want a simpler option, then you can read xml through \Zend\Config\Reader\Xml and feed it to the default factory, but then xml will have to be adjusted to the specification.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question