#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    PEAR XML_Serializer inserting unwanted tags


    I create an array, then push 0..n elements onto one of the subarrays within the array (easiest to see what I mean in the code below).

    When I run the array through XML_Serializer, it adds extra tags around the pushed elements

    (Originally posted on StackOverflow with 0 responses - then I re-discovered devshed!)

    Code:
    $serializer_options = array(
        XML_SERIALIZER_OPTION_INDENT => '    ',
        XML_SERIALIZER_OPTION_RETURN_RESULT => TRUE,
        rootName => 'JZ_2103'
    );
    $serializer = &new XML_Serializer($serializer_options);
    
    $otXmlArr = array(
        'status' => 'success',
        'reason' => 'null',
        'payload' => array(
            'ContactsResponse' => array()
        )
    );
    
    foreach ($mydata as $item) {
        array_push($otXmlArr['payload']['ContactsResponse'],
            array(
                'Contact' => array(
                    'ID' => $item['id'],
                    'FirstName' => $item['fname']
                )
            )
        );
    }
    
    $otXml = $serializer->serialize($otXmlArr);
    The xml that is created has extra tags
    Code:
    <XML_Serializer_Tag>
    How do I eliminate these tags?

    Code:
    <JZ_2103>
        <status>success</status>
        <reason>null</reason>
        <payload>
            <ContactsResponse>
                <XML_Serializer_Tag>
                    <Contact>
                        <ID>10</ID>
                        <FirstName>Roy</FirstName>
                    </Contact>
                </XML_Serializer_Tag>
            </ContactsResponse>
        </payload>
    </JZ_2103>
  2. #2
  3. No Profile Picture
    Brony & F/OSS Advocate
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2003
    Location
    Anaheim, CA (USA)
    Posts
    6,653
    Rep Power
    2475
    Moved from Python Programming to PHP Development.
    ~~ Peter ~~ :: ( Who am I? ) :: ( Peter's Musings: Uploading myself, bit by bit... ) :: ( Electronic Frontier Foundation ) :: ( I'm a GNU/Linux addict and Free Software Advocate. ) :: ( How to Ask Questions the Smart Way ) :: ( The Fedora Project, sponsored by Red Hat ) :: ( GNOME: The Free Software Desktop Project ) :: ( GnuPG Public Key ) :: ( About me on the WIki )

IMN logo majestic logo threadwatch logo seochat tools logo