Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting php object to xml is not working #17

Open
sivakumargollu opened this issue Dec 4, 2014 · 10 comments
Open

Converting php object to xml is not working #17

sivakumargollu opened this issue Dec 4, 2014 · 10 comments

Comments

@sivakumargollu
Copy link

Dear Team,

Please help me out of this issue as i was stopped my further developement here and need deliver the product to within few days.

Untill now i had used level42 for UnMarshaling only. But as per my new requirement i have an multiple php objects which have to be converted to individual xmls. But here my problem some of object fragments are not converting to xml . Attached document contains the php object,my desired output,actual oupt and level 42 files i am using.

Kind Regards,
Siva Kumar.

@sivakumargollu
Copy link
Author

Expected output


image

Output


screenshot

Php object


Level42\CSI\Classes\Entities\Mail_Request Object
(
[mails:Level42\CSI\Classes\Entities\Mail_Request:private] => Array
(
[0] => Level42\CSI\Classes\Entities\Mails Object
(
[mail:Level42\CSI\Classes\Entities\Mails:private] => Array
(
[0] => Level42\CSI\Classes\Entities\Mail Object
(
[fromAddress:Level42\CSI\Classes\Entities\Mail:private] => Array
(
[0] => Level42\CSI\Classes\Entities\FromAddress Object
(
[fromAddress_value:Level42\CSI\Classes\Entities\FromAddress:private] => [email protected]
)

                                    )

                                [projectID:Level42\CSI\Classes\Entities\Mail:private] => 
                                [priority:Level42\CSI\Classes\Entities\Mail:private] => 
                                [mD5Force:Level42\CSI\Classes\Entities\Mail:private] => 
                                [mD5Delay:Level42\CSI\Classes\Entities\Mail:private] => 
                                [smsAlert:Level42\CSI\Classes\Entities\Mail:private] => 
                                [recipientAddresses:Level42\CSI\Classes\Entities\Mail:private] => Array
                                    (
                                        [0] => Level42\CSI\Classes\Entities\RecipientAddresses Object
                                            (
                                                [toList:Level42\CSI\Classes\Entities\RecipientAddresses:private] => Array
                                                    (
                                                        [0] => Level42\CSI\Classes\Entities\ToList Object
                                                            (
                                                                [emailID:Level42\CSI\Classes\Entities\ToList:private] => Array
                                                                    (
                                                                        [0] => Level42\CSI\Classes\Entities\EmailID Object
                                                                            (
                                                                                [emailID_value:Level42\CSI\Classes\Entities\EmailID:private] => [email protected]
                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [ccList:Level42\CSI\Classes\Entities\RecipientAddresses:private] => Array
                                                    (
                                                        [0] => Level42\CSI\Classes\Entities\CcList Object
                                                            (
                                                                [emailID:Level42\CSI\Classes\Entities\CcList:private] => Array
                                                                    (
                                                                        [0] => Level42\CSI\Classes\Entities\EmailID Object
                                                                            (
                                                                                [emailID_value:Level42\CSI\Classes\Entities\EmailID:private] => [email protected]
                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [bccList:Level42\CSI\Classes\Entities\RecipientAddresses:private] => Array
                                                    (
                                                        [0] => Level42\CSI\Classes\Entities\BccList Object
                                                            (
                                                                [emailID:Level42\CSI\Classes\Entities\BccList:private] => Array
                                                                    (
                                                                        [0] => Level42\CSI\Classes\Entities\EmailID Object
                                                                            (
                                                                                [emailID_value:Level42\CSI\Classes\Entities\EmailID:private] => [email protected]
                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [failOver:Level42\CSI\Classes\Entities\RecipientAddresses:private] => 
                                            )

                                    )

                                [attachments:Level42\CSI\Classes\Entities\Mail:private] => Array
                                    (
                                        [0] => Level42\CSI\Classes\Entities\Attachments Object
                                            (
                                                [attachment:Level42\CSI\Classes\Entities\Attachments:private] => Array
                                                    (
                                                        [0] => Level42\CSI\Classes\Entities\Attachment Object
                                                            (
                                                                [content:Level42\CSI\Classes\Entities\Attachment:private] => Array
                                                                    (
                                                                        [0] => Level42\CSI\Classes\Entities\Content Object
                                                                            (
                                                                                [param:Level42\CSI\Classes\Entities\Content:private] => Array
                                                                                    (
                                                                                    )

                                                                                [content_value:Level42\CSI\Classes\Entities\Content:private] => 
                                                                            )

                                                                    )

                                                                [name:Level42\CSI\Classes\Entities\Attachment:private] => CultAgent-ExtranetFeeder-yyyy-mm-dd hh:mm:ss.pdf
                                                                [type:Level42\CSI\Classes\Entities\Attachment:private] => pdf
                                                            )

                                                    )

                                            )

                                    )

                                [subject:Level42\CSI\Classes\Entities\Mail:private] => Array
                                    (
                                        [0] => Level42\CSI\Classes\Entities\Subject Object
                                            (
                                                [text:Level42\CSI\Classes\Entities\Subject:private] => Array
                                                    (
                                                    )

                                                [subject_value:Level42\CSI\Classes\Entities\Subject:private] => PDF WS generation
                                            )

                                    )

                                [body:Level42\CSI\Classes\Entities\Mail:private] => Array
                                    (
                                        [0] => Level42\CSI\Classes\Entities\Body Object
                                            (
                                                [text:Level42\CSI\Classes\Entities\Body:private] => Array
                                                    (
                                                        [0] => Level42\CSI\Classes\Entities\Text Object
                                                            (
                                                                [formatted:Level42\CSI\Classes\Entities\Text:private] => 
                                                                [language:Level42\CSI\Classes\Entities\Text:private] => 
                                                                [text_value:Level42\CSI\Classes\Entities\Text:private] => This is for you kind information
                                                            )

                                                    )

                                                [type:Level42\CSI\Classes\Entities\Body:private] => 
                                            )

                                    )

                                [getMailStatus:Level42\CSI\Classes\Entities\Mail:private] => 
                                [getMailContent:Level42\CSI\Classes\Entities\Mail:private] => 
                                [getReSentMailID:Level42\CSI\Classes\Entities\Mail:private] => 
                                [getOriginalRQ:Level42\CSI\Classes\Entities\Mail:private] => 
                                [iD:Level42\CSI\Classes\Entities\Mail:private] => 
                                [mailStatus:Level42\CSI\Classes\Entities\Mail:private] => 
                                [mailContent:Level42\CSI\Classes\Entities\Mail:private] => 
                                [reSentMailID:Level42\CSI\Classes\Entities\Mail:private] => 
                                [originalRequest:Level42\CSI\Classes\Entities\Mail:private] => 
                                [error:Level42\CSI\Classes\Entities\Mail:private] => 
                            )

                    )

            )

    )

)

@yann-eugone
Copy link

I'm really sorry but your PHP Object output is unreadable as is...

Can you please paste us the Marshalling configuration for your objects ?

@sivakumargollu
Copy link
Author

Thank you very much for your immediate response.

Really very sorry to says that i don't have any basic idea of "Marshalling configuration" and where to find this file.Could please tell me the path where to find the configuration of Marshalling.

Please refer below lines.

Each and every class have the following declaration before class definition.

namespace Level42\CSI\Classes\Entities;

use Level42\NotJaxbBundle\Annotation\XmlAttribute;
use Level42\NotJaxbBundle\Annotation\XmlElement;
use Level42\NotJaxbBundle\Annotation\XmlList;
use Level42\NotJaxbBundle\Annotation\XmlObject;
use Level42\NotJaxbBundle\Annotation\XmlValue;

My seniors have provided the following class for marshalling and unmarshalling....Now i am using object_2_xml() and xml_2_object methods.

xmlUnmarshalling === null) { $cacheDir = __DIR__ . '/../../../cache/notjaxb-mapping-xml'; // Must be change $maxDepth = 20; // limit recursion $useCache = false; // set debug mode (no cache) $this->xmlUnmarshalling = new \Level42\NotJaxbBundle\Manager\XmlUnmarshalling( new \Level42\NotJaxbBundle\Mapping\ClassMetadataFactory( new \Level42\NotJaxbBundle\Annotation\AnnotationLoader( new \Doctrine\Common\Annotations\FileCacheReader( new \Doctrine\Common\Annotations\AnnotationReader(), $cacheDir, !$useCache), $maxDepth) ) ); } return $this->xmlUnmarshalling; } public function getMarshallerInstance() { if ($this->xmlMarshalling === null) { $cacheDir = __DIR__ . '/../../../cache/notjaxb-mapping-xml'; // Must be change $maxDepth = 20; // limit recursion $useCache = false; // set debug mode (no cache) $this->xmlMarshalling = new \Level42\NotJaxbBundle\Manager\XmlMarshalling( new \Level42\NotJaxbBundle\Mapping\ClassMetadataFactory( new \Level42\NotJaxbBundle\Annotation\AnnotationLoader( new \Doctrine\Common\Annotations\FileCacheReader( new \Doctrine\Common\Annotations\AnnotationReader(), $cacheDir, !$useCache), $maxDepth) ) ); } return $this->xmlMarshalling; } public function object_2_xml($object) { $xml = $this->getMarshallerInstance()->marshall($object); //echo "Object has converted to xml".$xml; return $xml; } public function xml_2_object($xml,$rootTag = null) { if(is_null($rootTag)) $rootTag = '\Level42\CSI\Classes\Entities\OTA_HotelDescriptiveInfoRS'; else $rootTag = '\Level42\CSI\Classes\Entities\\'.$rootTag; $object = $this->getUnmarshallerInstance()->unmarshall(trim($xml),$rootTag); return $object; } public function testFullMarshalling() { //echo "In the test full marshalling
"; $xml = $this->getMarshallerInstance()->marshall($toMarshall); $xmlcommunicator = new \XMLCommunicator(); $xmlResponse = $xmlcommunicator->sendXMLdata(stripslashes(trim($xml))); //echo '
XmlResponse:'.$xmlResponse $xmlParseObject = $this->testFullUnmarshalling($xmlResponse); return $xmlParseObject; } public function testFullUnmarshalling($xml) { $xmlResponse = trim($xml); #echo '
XmlResponse' . $xmlResponse; $ParseObject = $this->getUnmarshallerInstance()->unmarshall($xmlResponse, '\Level42\CSI\Classes\Entities\OTA_HotelDescriptiveInfoRS'); return $ParseObject; } ``` }

@yann-eugone
Copy link

Marshalling configuration

Your objects classes must be configured to be parsed as XML using the annotations XmlAttribute, XmlElement, etc... as described in the doc

How you are doing

If you are in a Symfony project, you must use the provided service as described in the doc

@sivakumargollu
Copy link
Author

I am on yii project using level42 for unmarshalling untill now.

Yes,I am doing same way as mentioned in the given link.

Please find the following class.

toList; } public function setToList($toList) { $this->toList[] = $toList; } /** - @xmllist(name="CcList",type="\Level42\CSI\Classes\Entities\CcList") */ private $ccList; public function getCcList() { return $this->ccList; } public function setCcList($ccList) { $this->ccList[] = $ccList; } /** - @xmllist(name="BccList",type="\Level42\CSI\Classes\Entities\BccList") */ private $bccList; public function getBccList() { return $this->bccList; } public function setBccList($bccList) { $this->bccList[] = $bccList; } /** - @xmllist(name="FailOver",type="\Level42\CSI\Classes\Entities\FailOver") */ private $failOver; public function getFailOver() { return $this->failOver; } public function setFailOver($failOver) { $this->failOver[] = $failOver; } }

@sivakumargollu
Copy link
Author

Dear Yann Eugoné,

While trying to get out of this issue i noticed that metadata of my
"RecipientAddresses"
class seem quite different from other classes metadaa as it doesn't
contains the information about its sub-tags. This information may help you
to understand my problem.

Attached document contains the my RecipientAddresses class and it's
metadata generated in XmlMarshalling.marshall() method

MetaData of RecipientAddresses


On Thu, Dec 4, 2014 at 4:04 PM, Yann Eugoné [email protected]
wrote:

Marshalling configuration

Your objects classes must be configured to be parsed as XML using the
annotations XmlAttribute, XmlElement, etc... as described in the doc
https://github.com/Level42/NotJaxbBundle/blob/master/Resources/doc/README_en.md#21-annotations
How you are doing

If you are in a Symfony project, you must use the provided service as
described in the doc
https://github.com/Level42/NotJaxbBundle/blob/master/Resources/doc/README_en.md#use

Reply to this email directly or view it on GitHub
#17 (comment)
.

[RecipientAddresses] => Array
(
[0] => attachments
[1] =>
[2] => Level42\NotJaxbBundle\Mapping\ClassMetadata Object
(
[reflClass:protected] => ReflectionClass Object
(
[name] => Level42\CSI\Classes\Entities\Attachments
)

                                                                        [name:protected] => Attachments
                                                                        [className:protected] => \Level42\CSI\Classes\Entities\Attachments
                                                                        [namespace:protected] => 
                                                                        [prefix:protected] => 
                                                                        [attributes:protected] => Array
                                                                            (
                                                                            )

                                                                        [elements:protected] => Array
                                                                            (
                                                                            )

                                                                        [embeds:protected] => Array
                                                                            (
                                                                            )

                                                                        [lists:protected] => Array
                                                                            (
                                                                                [Attachment] => Array
                                                                                    (
                                                                                        [0] => attachment
                                                                                        [1] => 
                                                                                        [2] => Level42\NotJaxbBundle\Mapping\ClassMetadata Object
                                                                                            (
                                                                                                [reflClass:protected] => ReflectionClass Object
                                                                                                    (
                                                                                                        [name] => Level42\CSI\Classes\Entities\Attachment
                                                                                                    )

                                                                                                [name:protected] => Attachment
                                                                                                [className:protected] => \Level42\CSI\Classes\Entities\Attachment
                                                                                                [namespace:protected] => 
                                                                                                [prefix:protected] => 
                                                                                                [attributes:protected] => Array
                                                                                                    (
                                                                                                        [Name] => Array
                                                                                                            (
                                                                                                                [0] => name
                                                                                                                [1] => 
                                                                                                                [2] => 
                                                                                                                [3] => 
                                                                                                            )

                                                                                                        [Type] => Array
                                                                                                            (
                                                                                                                [0] => type
                                                                                                                [1] => 
                                                                                                                [2] => 
                                                                                                                [3] => 
                                                                                                            )

                                                                                                    )

                                                                                                [elements:protected] => Array
                                                                                                    (
                                                                                                    )

                                                                                                [embeds:protected] => Array
                                                                                                    (
                                                                                                    )

                                                                                                [lists:protected] => Array
                                                                                                    (
                                                                                                        [Content] => Array
                                                                                                            (
                                                                                                                [0] => content
                                                                                                                [1] => 
                                                                                                                [2] => Level42\NotJaxbBundle\Mapping\ClassMetadata Object
                                                                                                                    (
                                                                                                                        [reflClass:protected] => ReflectionClass Object
                                                                                                                            (
                                                                                                                                [name] => Level42\CSI\Classes\Entities\Content
                                                                                                                            )

                                                                                                                        [name:protected] => Content
                                                                                                                        [className:protected] => \Level42\CSI\Classes\Entities\Content
                                                                                                                        [namespace:protected] => 
                                                                                                                        [prefix:protected] => 
                                                                                                                        [attributes:protected] => Array
                                                                                                                            (
                                                                                                                            )

                                                                                                                        [elements:protected] => Array
                                                                                                                            (
                                                                                                                            )

                                                                                                                        [embeds:protected] => Array
                                                                                                                            (
                                                                                                                            )

                                                                                                                        [lists:protected] => Array
                                                                                                                            (
                                                                                                                                [Param] => Array
                                                                                                                                    (
                                                                                                                                        [0] => param
                                                                                                                                        [1] => 
                                                                                                                                        [2] => Level42\NotJaxbBundle\Mapping\ClassMetadata Object
                                                                                                                                            (
                                                                                                                                                [reflClass:protected] => ReflectionClass Object
                                                                                                                                                    (
                                                                                                                                                        [name] => Level42\CSI\Classes\Entities\Param
                                                                                                                                                    )

                                                                                                                                                [name:protected] => Param
                                                                                                                                                [className:protected] => \Level42\CSI\Classes\Entities\Param
                                                                                                                                                [namespace:protected] => 
                                                                                                                                                [prefix:protected] => 
                                                                                                                                                [attributes:protected] => Array
                                                                                                                                                    (
                                                                                                                                                        [Name] => Array
                                                                                                                                                            (
                                                                                                                                                                [0] => name
                                                                                                                                                                [1] => 
                                                                                                                                                                [2] => 
                                                                                                                                                                [3] => 
                                                                                                                                                            )

                                                                                                                                                        [Value] => Array
                                                                                                                                                            (
                                                                                                                                                                [0] => value
                                                                                                                                                                [1] => 
                                                                                                                                                                [2] => 
                                                                                                                                                                [3] => 
                                                                                                                                                            )

                                                                                                                                                        [CodeDetails] => Array
                                                                                                                                                            (
                                                                                                                                                                [0] => codeDetails
                                                                                                                                                                [1] => 
                                                                                                                                                                [2] => 
                                                                                                                                                                [3] => 
                                                                                                                                                            )

                                                                                                                                                    )

                                                                                                                                                [elements:protected] => Array
                                                                                                                                                    (
                                                                                                                                                    )

                                                                                                                                                [embeds:protected] => Array
                                                                                                                                                    (
                                                                                                                                                    )

                                                                                                                                                [lists:protected] => Array
                                                                                                                                                    (
                                                                                                                                                        [ParamData] => Array
                                                                                                                                                            (
                                                                                                                                                                [0] => paramData
                                                                                                                                                                [1] => 
                                                                                                                                                                [2] => Level42\NotJaxbBundle\Mapping\ClassMetadata Object
                                                                                                                                                                    (
                                                                                                                                                                        [reflClass:protected] => ReflectionClass Object
                                                                                                                                                                            (
                                                                                                                                                                                [name] => Level42\CSI\Classes\Entities\ParamData
                                                                                                                                                                            )

                                                                                                                                                                        [name:protected] => ParamData
                                                                                                                                                                        [className:protected] => \Level42\CSI\Classes\Entities\ParamData
                                                                                                                                                                        [namespace:protected] => 
                                                                                                                                                                        [prefix:protected] => 
                                                                                                                                                                        [attributes:protected] => Array
                                                                                                                                                                            (
                                                                                                                                                                                [Name] => Array
                                                                                                                                                                                    (
                                                                                                                                                                                        [0] => name
                                                                                                                                                                                        [1] => 
                                                                                                                                                                                        [2] => 
                                                                                                                                                                                        [3] => 
                                                                                                                                                                                    )

                                                                                                                                                                                [Value] => Array
                                                                                                                                                                                    (
                                                                                                                                                                                        [0] => value
                                                                                                                                                                                        [1] => 
                                                                                                                                                                                        [2] => 
                                                                                                                                                                                        [3] => 
                                                                                                                                                                                    )

                                                                                                                                                                            )

                                                                                                                                                                        [elements:protected] => Array
                                                                                                                                                                            (
                                                                                                                                                                            )

                                                                                                                                                                        [embeds:protected] => Array
                                                                                                                                                                            (
                                                                                                                                                                            )

                                                                                                                                                                        [lists:protected] => Array
                                                                                                                                                                            (
                                                                                                                                                                            )

                                                                                                                                                                        [value:protected] => 
                                                                                                                                                                    )

                                                                                                                                                                [3] => 
                                                                                                                                                                [4] => ParamData
                                                                                                                                                                [5] => 
                                                                                                                                                            )

                                                                                                                                                    )

                                                                                                                                                [value:protected] => 
                                                                                                                                            )

                                                                                                                                        [3] => 
                                                                                                                                        [4] => Param
                                                                                                                                        [5] => 
                                                                                                                                    )

                                                                                                                            )

                                                                                                                        [value:protected] => content_value
                                                                                                                    )

                                                                                                                [3] => 
                                                                                                                [4] => Content
                                                                                                                [5] => 
                                                                                                            )

                                                                                                    )

                                                                                                [value:protected] => 
                                                                                            )

                                                                                        [3] => 
                                                                                        [4] => Attachment
                                                                                        [5] => 
                                                                                    )

                                                                            )

                                                                        [value:protected] => 
                                                                    )

                                                                [3] => 
                                                                [4] => RecipientAddresses
                                                                [5] => 
                                                            )

@yann-eugone
Copy link

I'm really sorry but the output you paste is not readable, please try something else than copy/pasting a var_dump if you want some help.

@sivakumargollu
Copy link
Author

Dera yann-eugone,
Thank you very much for your response.
I have found why tag hasn't set properly in the xml. It is because of the wrong annotation declaration before class definition. Now it is resolved.

Now another issue i am facing that,I am using the above xml to send mail to client with help of WebService developed by another team . This webservice accepts the data of some xml elements in CDATA only. For example "Subject" value should be passed like below

image
but mashalling generating following out put like
image

Do i need extra configuration for it?

My Subject class is


subject_value; ``` } public function setSubject_value($subject_value) { ``` $this->subject_value = $subject_value; ``` } }

@yann-eugone
Copy link

We did not develop a way to configure the CDATA section appending...
I assume this can be a problem for you.
You can try implementing your own marshalling object, extending our, and overriding the parse* methods.
You can also make a PR with the functionnality, we will try to merge it.

@sivakumargollu
Copy link
Author

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants