Code Monkey home page Code Monkey logo

Comments (5)

goetas avatar goetas commented on May 25, 2024

Have you tried to follow the guide (explained here)?

from xsd2php.

tvaughan73 avatar tvaughan73 commented on May 25, 2024

I have tried but I am getting the error:

[17-May-2017 18:33:14 America/New_York] PHP Fatal error:  Uncaught exception 'JMS\Serializer\Exception\XmlErrorException' with message '[FATAL] Specification mandate value for attribute xml
 in  (line: 1, column: 10)' in /home/dev/public_html/application/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php:84
Stack trace:
#0 /home/dev/public_html/application/vendor/jms/serializer/src/JMS/Serializer/Serializer.php(128): JMS\Serializer\XmlDeserializationVisitor->prepare('<some xml/>')
#1 [internal function]: JMS\Serializer\Serializer->JMS\Serializer\{closure}(Object(JMS\Serializer\XmlDeserializationVisitor))
#2 /home/dev/public_html/application/vendor/phpoption/phpoption/src/PhpOption/Some.php(89): call_user_func(Object(Closure), Object(JMS\Serializer\XmlDeserializationVisitor))
#3 /home/dev/public_html/application/vendor/jms/serializer/src/JMS/Serializer/Serializer.php(132): PhpOption\Some->map(Object(Closure))
#4 /home/dev/public_html/application/controllers/test.php(37): JMS\Serializer\Serializer->deserialize('<some xml/>', 'TestNs\\MyObject', 'xm in /home/dev/public_html/application/vendor/jms/serializer/src/JMS/Serializer/XmlDeserializationVisitor.php on line 84

Here is code:

        $serializerBuilder = SerializerBuilder::create();
        $serializerBuilder->addMetadataDir('/home/dev/public_html/soap/metadata', 'TestNs');
        $serializerBuilder->configureHandlers(function (HandlerRegistryInterface $handler) use ($serializerBuilder) {
            $serializerBuilder->addDefaultHandlers();
            $handler->registerSubscribingHandler(new BaseTypesHandler()); // XMLSchema List handling
            $handler->registerSubscribingHandler(new XmlSchemaDateHandler()); // XMLSchema date handling
        });

        $serializer = $serializerBuilder->build();

        // deserialize the XML into Demo\MyObject object
        $object = $serializer->deserialize('<some xml/>', 'TestNs\MyObject', 'xml');

        // some code ....

        // serialize the Demo\MyObject back into XML
        $newXml = $serializer->serialize($object, 'xml');

I suspect that something else is supposed to go into the deserialize method besides '' but I don't know what.

from xsd2php.

tvaughan73 avatar tvaughan73 commented on May 25, 2024

Ok so I decided to start over using a simple xsd I found:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://tempuri.org/PurchaseOrderSchema.xsd"
           targetNamespace="http://tempuri.org/PurchaseOrderSchema.xsd"
           elementFormDefault="qualified">
 <xsd:element name="PurchaseOrder" type="tns:PurchaseOrderType"/>
 <xsd:complexType name="PurchaseOrderType">
  <xsd:sequence>
   <xsd:element name="ShipTo" type="tns:USAddress" maxOccurs="2"/>
   <xsd:element name="BillTo" type="tns:USAddress"/>
  </xsd:sequence>
  <xsd:attribute name="OrderDate" type="xsd:date"/>
 </xsd:complexType>

 <xsd:complexType name="USAddress">
  <xsd:sequence>
   <xsd:element name="name"   type="xsd:string"/>
   <xsd:element name="street" type="xsd:string"/>
   <xsd:element name="city"   type="xsd:string"/>
   <xsd:element name="state"  type="xsd:string"/>
   <xsd:element name="zip"    type="xsd:integer"/>
  </xsd:sequence>
  <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
 </xsd:complexType>
</xsd:schema>

config.yml

xsd2php:
  namespaces:
    'http://tempuri.org/PurchaseOrderSchema.xsd': 'TestNs\MyApp'
  destinations_php:
    'TestNs\MyApp': soap2/src
  destinations_jms:
    'TestNs\MyApp': soap2/metadata
  naming_strategy: short # optional and default
  path_generator: psr4 # optional and default

Generated PHP classes and metadata OK. The generated PHP classes are PurchaseOrder.php, PurchaseOrderType.php, and USAddressType.php.

I don't understand what I am supposed to do next. Is there a start to finish example anywhere?

from xsd2php.

goetas avatar goetas commented on May 25, 2024

it looks your XML is not well formatted (this is an example of a document that triggers a similar error http://www.getsymphony.com/discuss/thread/107805/)

from xsd2php.

kiranphp avatar kiranphp commented on May 25, 2024

@rps-repo
Hii,
Please look at this https://github.com/goetas-webservices/xsd2php/issues/34 I ran into similar problem,if you need to generate XML, you first create the object set values to fields and then serialize it to XML.

from xsd2php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.