Re: simplexml problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nathan Nobbe escribió:
On Dec 31, 2007 7:11 AM, Dani Castaños <danitao.mailists@xxxxxxxxx <mailto:danitao.mailists@xxxxxxxxx>> wrote:

    Hi all!

    I'm using simplexml to load an xml into an object.
    The XML is this:
    <?xml version="1.0"?>
    <request>
     <customerID>3</customerID>
     <appName>agenda</appName>
     <ticketType>cticket_agenda_server</ticketType>
     <ticketTypeID>1</ticketTypeID>
     <platformID>1</platformID>
     <ticketAction>addUsersToGroup</ticketAction>
    </request>

    When I do this:

    $file = simplexml_load_file( 'file.xml' );
    $ticketType = $file->ticketType;

    What i really have into $ticketType is a SimpleXMLElement... not the
value "cticket_agenda_server"... What am I doing wrong?

cast the value to a string when you pull it out if you want to use it that way:

<?php
$xml =
<<<XML
<?xml version="1.0"?>
<request>
 <customerID>3</customerID>
 <appName>agenda</appName>
 <ticketType>cticket_agenda_server</ticketType>
 <ticketTypeID>1</ticketTypeID>
 <platformID>1</platformID>
 <ticketAction>addUsersToGroup</ticketAction>
</request>
XML;

$file = new SimpleXMLElement($xml);
$ticketTypeAsSimpleXmlElement = $file->ticketType;
$ticketTypeAsString = (string)$file->ticketType;
$ticketTypeAnalyzer = new ReflectionObject($ticketTypeAsSimpleXmlElement);

echo (string)$ticketTypeAnalyzer . PHP_EOL;
var_dump($ticketTypeAsString);
?>

-nathan



Thanks! Problem fixed... But I think PHP must do the cast automatically. I think it's a bug fixed in a further version than mine as I've read

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux