Re: [PHP] simplexml problem



On Dec 31, 2007 7:11 AM, Dani Castaños <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


Relevant Pages

  • Re: [PHP] simplexml problem
    ... I'm using simplexml to load an xml into an object. ... But I think PHP must do the cast automatically. ...
    (php.general)
  • simplexml problem
    ... I'm using simplexml to load an xml into an object. ... Uncaught exception 'Exception' with message 'SimpleXMLElement::__constructexpects parameter 1 to be string, ... It seems like it uses $ticketType class instead the value inside. ...
    (php.general)
  • Re: Design involving composition of inherited members.
    ... I am designing classes to work with an API. ... The API operates via XML ... Each API call involves sending a request and ... If the data packets' semantics are unique to each messageID, then each API method would know which particular serialization to use. ...
    (comp.object)
  • Re: IIS returns status code 200 even if XML is invalid
    ... ASMX requests are handled by ASP.NET ... when there is a problem with an XML being sent to the server ... The request is not being handled by the "designated method" which ... That HTTP 1.1 200 OK return code means the the HTTP request/connection ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: reading a XML file on every page execution - convert to PHP?
    ... into a simpleXML node every time index.php loads. ... Including a php file requires the file be read then parsed. ... modification date- and use the .xml only if it was newer. ... cannot load, ...
    (comp.lang.php)