Level42 / NotJaxbBundle

A Symfony 2 bundle to bind XML to PHP objects or PHP objects to XML using annotations
MIT License
3 stars 2 forks source link

Conflict with tag having both the xml value and xml element #16

Open narayanamurthy opened 9 years ago

narayanamurthy commented 9 years ago

I'm having a problem while preparing XML. If a tag contains both the sub-tags and value( yeah i have different XMLs ) and when i'm trying to set sub-tags it doesn't work and it only sets attributes or value not the sub-tags.

Here is the example from two XMLs.

  1.     <Body type="plain">
           <Text>Dear test,
               For your Information.,
               Kind Regards,
               test
           </Text>
       </Body>
  2.    <Subject> 
            Test mail
       </Subject>
       <Body Type="html">This is the sample text.</Body>
       <ToAddresses>test@gmail.com,rest@gmail.com</ToAddresses>
       <CcAddresses>test@gmail.com</CcAddresses>
       <BccAddresses>test@gmail.com</BccAddresses>
       <TemplateID>2123</TemplateID>
yann-eugone commented 9 years ago

Can you paste your marshalling model configuration ?

narayanamurthy commented 9 years ago

Dear Yann Eugoné,

I am really sorry to say that I really do not know about "marshallong entities configuration".

Kind Regards, Narayana Murthy

On Wed, Dec 3, 2014 at 2:32 PM, Yann Eugoné notifications@github.com wrote:

Can you paste your marshallong entities configuration ?

— Reply to this email directly or view it on GitHub https://github.com/Level42/NotJaxbBundle/issues/16#issuecomment-65374646 .

yann-eugone commented 9 years ago

Ok, this Bundle is trying to achieve XML to object mapping, so it can help you building the (de)serialization (called marshalling and unmarshalling) rules of your objects to(from) XML.

But the bundle is not able to do this without some configuration...

Please read the doc

narayanamurthy commented 9 years ago

Thanks for the reply. I understand that the Bundle is not able to convert( Marshall ) object into XML. But where can I change the configuration in this library.

yann-eugone commented 9 years ago

This Bundle IS able to :

Let's take an example

With the class :

namespace My\Bundle\Model;

use Level42\NotJaxbBundle\Annotation as Marshall;

/**
 * @Marshall\XmlObject(name="email")
 */
class Email
{
    /**
     * @Marshall\XmlElement(name="Subject")
     */
    protected $subject;

    /**
     * @Marshall\XmlElement(name="ToAddresses")
     */
    protected $toAddresses;
}

You can get such a XML :

<email>
    <Subject>Test mail</Subject>
    <ToAddresses>test@gmail.com,rest@gmail.com</ToAddresses>
</email>
narayanamurthy commented 9 years ago

If also contails value like

testemail@test.com

the email class looks like this


/* * @Marshall\XmlValue / protected $email_value;


Now when i am trying to set or its not working. If I remove the above fraction of code it is working fine. I do not know whats the problem. Hope you understood my problem.

yann-eugone commented 9 years ago

Ok, if I understand your need, you got such a XML ?

<email>
    testemail@test.com 
    <Subject>Test mail</Subject>
    <ToAddresses>test@gmail.com,rest@gmail.com</ToAddresses>
</email>
narayanamurthy commented 9 years ago

No I do not have an xml like that. But I'm using different xmls which have common Tags.

Like in 1st xml

testmail.test.com

in 2nd xml

Test mail test@gmail.com,rest@gmail.com

and I created class for "email" depending on the above two xmls. And i got stuck here.

On Wed, Dec 3, 2014 at 4:35 PM, Yann Eugoné notifications@github.com wrote:

Ok, if I understand your need, you got such a XML ?

testemail@test.com Test mail test@gmail.com,rest@gmail.com

— Reply to this email directly or view it on GitHub https://github.com/Level42/NotJaxbBundle/issues/16#issuecomment-65391445 .

yann-eugone commented 9 years ago

Ok, I will have a look and try to reproduce to your issue later.

You can try using XmlRaw until we found a solution.

yann-eugone commented 9 years ago

So, I tested your use case, and I got the same problem. I think that this is caused by XmlValue, overriding the XML content within the marshalling process.

I created a new branch.

@fperinel what do you think we can do for this ?