#1
  1. doesn't like link-rollover ads
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Sep 2003
    Posts
    1,820
    Rep Power
    150

    XML schema binding to PHP code (jaxb equivalent?)


    anybody aware of a project to implement something similar to Java's JAXB (http://java.sun.com/xml/jaxb/about.html)?

    as i understand it, generates code on-the-fly from an XML schema such as XSD doc. also does marshalling/unmarshalling and data validation. a use case for elaboration would be:

    - read in an XSD document
    - appropriate classes are generated on the fly
    - coder instantiates objects from those classes, calls accessor methods to fill in data
    - finally make a call to marshal the data into an XML document
    - able to unmarshal that same XML document into replicas of the original objects


    is something like that out there? anybody interested in such a project?
  2. #2
  3. No Profile Picture
    Always Learning
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2002
    Location
    Port Neches, TX, USA
    Posts
    1,173
    Rep Power
    16
    There is not anything like this to my knowledge for PHP. Basically you want to feed a script an XSD and have it create a class to marshal/unmarshal XML data. PHP supports WSDL, XML and XSLT but there are no XSD extensions, so you'd be looking at undertaking a fairly sizeable project.

    I'd be interested if you're paying - drop me a line on msn messenger, hnr_louder@msn.com or on AIM, laynestaley02 if you want to talk.
    David Fells
    If my post helped you, please click the above my post and leave a comment. Thanks
  4. #3
  5. doesn't like link-rollover ads
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Sep 2003
    Posts
    1,820
    Rep Power
    150
    your payoff would be the knowledge of a job done well, creating a useful tool for the community i've got no money for you, i'm just some guy.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    6
    Rep Power
    0

    Thumbs up


    Originally Posted by n.eby
    your payoff would be the knowledge of a job done well, creating a useful tool for the community i've got no money for you, i'm just some guy.

    Well I was also looking for the same thing so it would be very helpful if we could share our findings.

    Mail me at mailpankaj007@yahoo.com

    Regards,
    Pankaj
  8. #5
  9. doesn't like link-rollover ads
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Sep 2003
    Posts
    1,820
    Rep Power
    150
    Nearly 2 years later and I came back around to the source of my original post on this topic. I still want a fully featured pure-PHP-code XML schema binding facility. There is no project out there; AFAIK there is also no PHP extension for such a project.

    Anyway, here is my solution for the time being. It is a long ways short of being able to bind even a fraction of the breadth of possible XML schemas. Really it's only good for one very narrow use case that I'll describe below. I may expand on it, I may not, but there it is.

    This works if your schema follows some conventions in my narrow use case:
    • contains some complexType nodes that you want to turn into classes named after the containing <element>
    • a complexType can have <attribute ref=""> referring by name to global <attribute> nodes
    • a complexType can have either <simpleContent> or <sequence>
    • <sequence> can have <group ref=""> referring by name to global <group> nodes; <element ref=""> referring by name to global element nodes; and <choice> nodes.

    Classes bound to complexType with sequences will have protected members for every <element> and <attribute> contained in the <complexType>, and for any <element> in any referred-to <group>. a camelCase naming convention is used for the class members.

    Classes bound to complexType nodes containing only a simpleContent node, will have a protected member called $value.

    The bound classes are, in my design, supposed to extend a class that provides automatic accessor methods for any public or protected member of child instances. So protected $foo will correspond with getFoo() and setFoo(). This is fairly academic to implement using php5's overloading features but if you want to see it, post a message here and I will probably notice and I can find and post the code.

    Usage for this class, which is called XmlSchemaBinding: assuming mySchema.xsd has a complexType-containing element with name like "the-struct" or "theStruct". A new class called TheStruct will be created and put in scope. If you specify the base-class parameter to constructor, TheStruct class will extend that class.
    PHP Code:
    $binding = new XmlSchemaBinding("/path/to/mySchema.xsd"[, "XsdBaseClass"]);
    $struct = new TheStruct();
    $struct->setFoo();
    $struct->setBar();
    $xml $binding->marshalXml($struct); 
    Code is attached. Yes it uses eval(), so sue me.
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo