Simplexml_load PHP with CDATA

Hello world!

I'm trying to scrape some data from an XML file that contains the content inside CDATA tags and I have a problem with it.

pet food. XML file:

<? XML version = "1.0" encoding = "UTF-8"? >

< String >

< item >

< pubDate > <! [CDATA [Thursday, September 17, 2015 16:02:53-0700]] > < / pubDate >

< title > <! [CDATA [hello world!]] > < / title >

< url > <! [CDATA [http://example.com/?id=hello_world]] > < / url >

< / point >

< / channel >

PHP:

<? PHP

If (file_exists ("feed.xml")) {}

$xml = simplexml_load_file ('feed.xml');

echo $xml-> channel-> item-> pubDate;

} else {}

output ("Failed to open xml.'");

}

? >

Error:

Try to get the property of the non-object in feed.xml

If I print_r $xml

I have a table of nodes, but no content [CDATA] tags.

What Miss me?

Nancy O.

It looks like $xml may be back your "channel" level so rather try echo $xml-> point-> pubDate;

Also, you can have more than one array element. In this case, you must specify which element of the table you want data for, such as echo $xml > item [0]-> pubDate;

Give any of these suggestions a shot and see if it works. FWIW discussion on php.net for simplexml_load_file() mention print_r not returning not content of CDATA but still being able to get it to properly qualifying.

Look at example 1 at the bottom of page to PHP function simplexml_load_file()

Their call is $xml echo-> echo $xml-> note not-> to

best,

Shocker

Tags: Coding Corner

Similar Questions

  • How to integrate a php with components file

    Hello

    How to integrate my php server diff with http://testby1234.herokuapp.com/ code

    http://testby1234.herokuapp.com/

    The url above is my simple component. I have php on my server from domain and diff diff files. How to integrate the PHP with my component? So when the eloqua user to use my component and double click it, and then open the php file.

    Thank you

    This is accomplished through endpoint URL configuration of the definition of the servicefrom your provider.

  • Request, the response of webservice with CDATA

    I need assistance with the query:

    declare

    Xml_RESPONSE Xmltype: = xmltype)

    ' ' < SOAP - ENV:Envelope xmlns:SOAP - ENV = " http://schemas.xmlsoap.org/SOAP/envelope/ "" xmlns: xsi = " " http://www.w3.org/2001/XMLSchema-instance "container =" " http://www.w3.org/2001/XMLSchema ">

    < SOAP - ENV:Body >

    " < ns1:Person1sResponse SOAP - ENV:encodingStyle = ' http://schemas.xmlsoap.org/SOAP/encoding/ "xmlns:ns1 ="MAP112"> "

    < back xsi: type = "xsd: String" > <! [CDATA [< person Ident1 = "234" > < 47 > < / Age > < Day_Time > 2015 - SEP - 03 08:55:43 < / Day_Time > < / person >]] > < / return >

    < / ns1:Person1sResponse >

    < / SOAP - ENV:Body >

    (< / SOAP - ENV:Envelope > ');

    BEGIN

    C IN)

    SELECT B2.*

    FROM XMLTable)

    XMLNamespaces)

                 ' http://schemas.xmlsoap.org/SOAP/envelope/ ' AS "SOAP-ENV"

    , "MAP112" AS "ns1."

    )

    , ' SOAP - ENV:Envelope / SOAP - ENV:Body / ns1:Person1sResponse / back '

    by the way Xml_RESPONSE

    path of columns person clob '.'

    ) A1

    XMLTable)

    "' / Person"

    by the way xmlparse (document A1. Person)

    age columns VARCHAR2 (10) PATH 'Age '.

    ) B2

    ) LOOP

    DBMS_OUTPUT. Put_line (' output: ' |) C.Age);

    END LOOP;

    END;

    Thank you

    Kostadin

    Your code is perfectly fine.

    What problem do you have?

    SQL> set serveroutput on
    SQL>
    SQL>
    SQL> declare
      2
      3  Xml_RESPONSE  Xmltype := xmltype(
      4  '
      5     
      6        
      7           4703-SEP-2015 08:55:43]]>
      8        
      9     
     10  ');
     11
     12  BEGIN
     13
     14  FOR C IN (
     15  SELECT B2.*
     16      FROM XMLTable(
     17             XMLNamespaces(
     18               'http://schemas.xmlsoap.org/soap/envelope/' AS "SOAP-ENV"
     19               ,'MAP112' AS  "ns1"
     20             )
     21           , 'SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:Person1sResponse/return'
     22             passing    Xml_RESPONSE
     23             columns Person  clob path '.'
     24          ) A1
     25        , XMLTable(
     26            '/Person'
     27            passing xmlparse(document A1.Person)
     28            columns     Age  VARCHAR2(10) PATH 'Age'
     29          ) B2
     30            ) LOOP
     31            DBMS_OUTPUT.PUT_LINE( 'output:    '|| C.Age   );
     32            END LOOP;
     33  END ;
     34  /
    
    output:    47
    
    PL/SQL procedure successfully completed.
    
  • Using PHP with Html5 Canvas in anime CC

    Someone at - it all the resources they can point me on the use of PHP in Html5 Canvas to animate CC?

    I don't seem to see a lot of options for this.

    We used to be able to with edge animate.

    Do you know how cool it would be to be able to build web applications Html5 using backend script just as you can on the side SWF (Flash) of things?

    In addition, anyone know what anime-road map will look like?

    Thanks in advance

    using animate than Pro, you can create an ajax function that allows you to send and load data from and to your php file.

    I use jquery because it longer resolves the differences between browsers in the processing of javascript.

  • Using PHP with Html5 Canvas in Flash CC

    Hello

    I know that I can make web applications using Flash CC *. Output SWF connect to PHP for the saving and loading of files.

    However, can I do the same web application publishing under an Easyjs HTML5 canvas, still using PHP for server tasks?

    Thank you

    SWFs communicate with their container via JavaScript pages.

    HTML5 Canvas mode (powered by CreateJS) uses no browser plugin, so its scripting JavaScript language.

    So yes, PHP and JavaScript and by extension of Web documents, can talk to each other.

  • OSB works differently with CDATA

    Hello

    I am applying to a webservice of px and bs, and I have two cases:

    <request>
    &lt;childs&gt;
    &lt;child0&gt;AAAA&lt;/child0&gt;
    &lt;/childs&gt;
    </request>
    

    with tcpddump, the result is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Header/>
      <soapenv:Body>
        <request>
          &lt;childs>&lt;child0>AAAA&lt;/child0>&lt;/childs>
        </request>
      </soapenv:Body>
    </soapenv:Envelope>
    

    this request doesn't use CDATA.

    <request>
    &lt;childs&gt;
    &lt;child0&gt;AAAA&lt;/child0&gt;
    &lt;child1&gt;AAAA&lt;/child1&gt;
    &lt;/childs&gt;
    </request>
    

    with tcpddump, the result is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Header/>
      <soapenv:Body>
        <request>
          <![CDATA[<childs><child0>AAAA</child0><child1>AAAA</child1></childs>]]>
        </request>
      </soapenv:Body>
    </soapenv:Envelope>
    

    This request uses CDATA

    Why use CDATA in option 2 and option 1?

    I guess General fresh CDATA (12 bytes) is greater than the savings (3 bytes per)<) for="" first="" call,="" and="" other="" way="" around="" for="" the="" second="">

    Indeed, in the first message 4< were="" escaped,="" making="" it="" 4x3="12" bytes="" overhead.="" cdata="" would="" take="" same="" 12.="" doesn't="" worth="">

    For the second message 6< would="" have="" to="" be="" escaped,="" 6x3="18" bytes="" overhead,="" while="" cdata="" still="" have="">

    You can test this theory by adding a single node to the first message. Should move to CDATA. \

    Vlad

    http://vladimirdyuzhev.com

  • How to generate xml with CDATA from a query

    I have the following query
    with data_tab as ( select 'Geetha' "code" ,'Book' "category" from dual union            
    select 'Nokia' "code" ,'mobile' "category" from dual )
    select Xmltype(cursor(select * from data_tab)) from dual
    and the output is
    <?xml version="1.0"?>
    <ROWSET>
     <ROW>
      <code>Geetha</code>
      <category>Book</category>
     </ROW>
     <ROW>
      <code>Nokia</code>
      <category>mobile</category>
     </ROW>
    </ROWSET>
    but I want to insert ot XML CDATA.
    Is that I need this xml file in the following format.
    <?xml version="1.0"?>
    <ROWSET>
     <ROW>
      <code>![CDATA[Geetha]]</code>
      <category>![CDATA[Book]]</category>
     </ROW>
     <ROW>
      <code>![CDATA[Nokia]]</code>
      <category>![CDATA[mobile]]</category>
     </ROW>
    </ROWSET>
    Please help me on this. In my original query, I am selecting from a record type, and it is nested. So I can not change the query select * from data_tab

    Manjusha Muraleedas wrote:
    Is there another solution.

    Well, Yes and no...

    No, because a CDATA section is supposed to be built directly on the data source, so that the content is preserved as is, with no escaped character.
    Yes, you can transform the XML to add CDATA sections thereafter, but what would be the point? The XMLType constructor already still escaped characters that are not valid.

    Out of curiosity, why do you require CDATA instead of escape sequences?

  • calculate a php with a new variable class

    I don't know what a class is. I have already written page that has in place for the equations. I have made new variables to a new equation but get incorrect results, I basically need multiple / divide / subtract these classes pre-generated against my new variable

    That's what I have so far

    <? PHP

    $utilityHost = 21.0;

    $col4 is $option_two-amount_due_before - $option_two-> four_weeks_security - $option_two-> tax >;.

    $col5 = $col4 / $row_Recordset1 ["rental_price"];

    $col3 = $utilityHost * $col5;

    $col6 = $row_Recordset1 ["rental_price"] * $col5;

    ? >

    $col4 is the variable using the pre built classes.

    all these are in fact the echo in a table

    for example

    <? PHP

    echo ' £» number_format ($row_Recordset1 ['rental_price'] - $utilityHost);

    ? >

    <? PHP

    echo ' £» $utilityHost;

    ? >

    classes

    <? PHP

    require_once('.. / lib/PaymentOptionOne.php');

    require_once('.. / lib/PaymentOptionTwo.php');

    require_once('.. / lib/PaymentOptionThree.php');

    require_once('.. / lib/PaymentOptionFour.php');

    $rent = $row_Recordset1 ["rental_price"];

    If ($row_Recordset1 ['weekly_rate']! = 0.00)

    $rent = $row_Recordset1 ["weekly_rate"];

    $weeks = $row_Recordset1 ["weeks"] / 7;

    $query = "SELECT * from editprop WHERE prop_id = %s ';

    $query is sprintf ($query, GetSQLValueString ($row_Recordset1 ['prop_id'], "text"));.

    $results = mysql_query ($query);

    While ($Row = mysql_fetch_array ($Results))

    {

    $option_three_rent = $row ["rental_price_monthly"];

    If (Empty ($option_three_rent))

    {

    $option_three_rent = $rent;

    }

    }

    $option_one = new PaymentOptionOne ($rent, $weeks);

    $option_two = new PaymentOptionTwo ($rent, $weeks);

    $option_three = new PaymentOptionThree ($option_three_rent, $weeks);

    Thanks in advance

    > multiple my variable with classes that are already in place

    The classes are complex constructions that contain data structures and methods. You do not have multiple variable with a class - you can reference a variable within the class or object. What exactly is the problem you're having with it?

    This syntax should work (note that I use arbitrary variables):

    $col4 = $option_two-> amount_due_before * $col2

    I think that it is essential that you are familiar with coding object-oriented if you go to work with her.

    http://www.elated.com/articles/object-oriented-PHP-for-absolute-beginners/

  • Basic in PHP with live preview support

    I use PHP includes when coding so I don't have to my navigation once the code, and then I can understand it on other pages. Is their anyway to make this work with Adobe Edge Code so I can't return to using .html files?

    If this isn't the case, I suppose I could rear transition, even if I'd really rather not.

    Thank you

    David Faircloth

    Hi Dave,.

    Edge Code Preview 2 we have added support for specifying a "Base URL" live preview (file > Project Settings...) so the files can be run on a server, including PHP.

    Have you tried, or is there something else you wanted? If so, please provide details.

    Thank you
    Randy

  • form php with html page?

    This is an excerpt from a short form, I would like to put up on my site in HTML single page. It is powered by PHP, and my intention is to insert this form in the footer of the site.

    Can I copy the code for the form and insert in my footer & who would do it? Just change the extension of the file to PHP to support and then make the call PHP at the top of page?

    And, if it becomes too difficult - how could I change the electronic form to HTML only if needed tag?

    < div class = "formblock" >

    < label = "howHeard" class = "text-reader-screen" > how did you hear about this? < / label >

    < select name = "howHeard" id = "howHeard" value = "<?" PHP if (isset($_POST['howHeard'])) echo $_POST ['howHeard'];? ">" class = "tick" >

    < option value = "volvo" > Volvo < / option >

    < option value = "saab" > Saab < / option >

    < option value = "mercedes" > Mercedes < / option >

    < option value = "audi" > Audi < / option >

    < / select >

    <? PHP if ($howHeardError! = ") {? >}

    < br / > < span class = "error" > <? PHP echo $howHeardError;? > < / span >

    <? PHP}? >

    < / div >

    Is it a good idea to make the HTML page in a PHP page? -Thanks!

    Can I copy the code for the form and insert in my footer & who would do it?

    Well, the extract is not form tags, and you will need a script for the treatment, which may be the same "page or another page. You also need a way to send the form.

    Is it a good idea to make the HTML page in a PHP page?

    The server must commit more resources to treat a PHP page, so you don't want to convert HTML pages to PHP pages unless there is code inside PHP. But there is no harm in turn an HTML page in a PHP page.

  • How to connect a PHP with sql server 2014 in dreamweaver

    I use Adobe Dreamweaver CS6 and I want to connect to the sql server database 2014 using PHP. I searched everywhere but still can't find the solution.

    You can access the database using PDO: http://php.net/manual/en/ref.pdo-sqlsrv.php

    There are official for generations

    You may need to install the drivers for SQL server PHP if you have not already.

  • What can I use PHP with Dreamweaver (was: php)

    Can I use php for scripts in dreamweaver cs5, on a windows server 2008

    Yes, you can use DW to create PHP scripts. If your windows server supports PHP (ask the host) these scripts will be executed.

  • problem with sending xml to php with URLRequest

    Okeay if someone could tell me what that is I am doing wrong? I get the following errors when I try to send the xml file to a php and write it in the xml file: #2044 Error: unhandled ioError:. Text = Error #2032: error flow.

    And my code is the following:

    Main application:

    <? XML version = "1.0" encoding = "utf-8"? >
    "" < mx:Application xmlns:mx = ' http://www.adobe.com/2006/mxml ' creationComplete = "LoadXML ()" layout = "absolute" > "
    < mx:Script source = "VieraskirjaScripti.as" / >
    < mx:DataGrid x = "10" y = "10" valueCommit = "out (event)" id = "mygrid" width = "245" height = "312" variableRowHeight = "true" > "
    < mx:columns >
    < mx:DataGridColumn headerText = "Vieraskijan merkinnät" textAlign = "center" fontFamily = "Georgia" fontSize = "15" fontWeight = "bold" = "col1" dataField >
    < mx:itemRenderer >
    < mx:Component >
    < mx:VBox >
    < mx:Text fontFamily = "Georgia" fontSize = "12" fontWeight = "normal" textAlign = "right" text = "{data.". Nimi} kirjoitti: "/ >"
    < mx:Text fontFamily = "Georgia" fontSize = "12" fontWeight = "normal" textAlign = "right" text = "{data.". Viesti} "/ >"
    < mx:Image source = "{data.". Kuva} "/ >"
    < / mx:VBox >
    < / mx:Component >
    < / mx:itemRenderer >
    < / mx:DataGridColumn >
    < / mx:columns >
    < / mx:DataGrid >
    < mx:Button = "201" x = "348" id = "Valamo" click = "LisaaUusi ()" label = "Button" / > "
    < mx:Button = "298" x = "348" label = "Save" click = "SaveXML (); grab. Text = str "/ >"
    < mx:TextArea = "263" x = "10" height = "312" width = "194" id = "grab" / >
    < / mx:Application >

    VieraskirjaScripti.as:

    ActionScript file
    Import mx.collections.XMLListCollection;
    Import mx.collections.Sort;
    Import mx.collections.SortField;
    flash.net import. *;
    import flash.events.Event;
    private var str:String;
    [Bindable]
    private var myXML:XML = new XML();

    private void LoadXML (): void {}
    var XML_URL:String = "Vieraskirja.xml";
    var myXMLURL:URLRequest = new URLRequest (XML_URL);
    myXMLURL.method = URLRequestMethod.POST;
    myXMLURL.data = myXML
    var myLoader:URLLoader = new URLLoader (myXMLURL);
    myLoader.addEventListener ("complete", xmlLoaded);
    }

    private void xmlLoaded(evtObj:Event):void {}
    var loader: URLLoader = URLLoader (evtObj.target);
    myXML = XML (loader.data);
    trace (myXML.Elements ('Merkinta'));
    mygrid.dataProvider = myXML.elements ('Merkinta');
    out (evtObj);
    }

    private void SaveXML (): void {}
    var PHP_URL:String = "Vieraskirja.PHP";
    var myPHPURL:URLRequest = new URLRequest (PHP_URL);
    myPHPURL.method = URLRequestMethod.POST;
    myPHPURL.contentType = "text/xml" ;// ' application/xml ';
    myPHPURL.data = myXML;
    var mySaver:URLLoader = new URLLoader (myPHPURL);
    mySaver.addEventListener ("complete", phpSaved);
    }
    private void phpSaved(evtObj:Event):void {}
    var Watch: URLLoader = URLLoader (evtObj.target);
    Str = saver.data;
    }
    private void LisaaUusi (): void {}
    var mychild:XML = < Merkinta >
    Pasi < Nimi > < / Nimi >
    123456789Pasi987654321 < Viesti > < / Viesti >
    Hymio02.gif < Kuva > < / Kuva >
    < Indeksi > 9 < / Indeksi >
    < / Merkinta >
    myXML = myXML.appendChild (mychild);
    trace (myGrid.DataProvider);
    mygrid.dataProvider = myXML.elements ('Merkinta');
    }

    private void sort(event:Event):void {}
    If (!) () mygrid.dataProvider == null)) {}
    var ac:XMLListCollection = XMLListCollection (mygrid.dataProvider);
    trace (AC);
    var sort: sort = new Sort();
    fate. Fields = [New, SortField ("Indeksi", true, true, true)];
    AC.sort = sort;
    AC. Refresh();
    Event.preventDefault ();
    }
    }

    N my php file:

    <? PHP
    $file = fopen ("Vieraskirja.xml", "w +") or die ("could not open XML file");
    $xmlString = $HTTP_RAW_POST_DATA;
    If (! fwrite ($file, $xmlString)) {}
    Print "error writing to an XML file.
    }
    print $xmlString. » \n » ;
    fclose ($file);
    ? >

    I just can't understand this

    EDiT: my vieraskirja test. XML looks like this:

    <? XML version = "1.0"? >
    < Vieraskirja >
    < Merkinta >
    Pasi < Nimi > < / Nimi >
    TestiViesti < Viesti > < / Viesti >
    Hymio02.gif < Kuva > < / Kuva >
    < Indeksi > 1 < / Indeksi > < / Merkinta >
    < Merkinta >
    < / Vieraskirja >

    A mistake is in your XML file. You have an additional label to at the end. It should be:



    PASI
    TestiViesti
    Hymio02.gif
    1

    But your error message looks like there is an error of path to locate your xml file or your PHP file. Make sure that the xml file is in the same directory as your swf file and also the PHP path is correct. When I tried your code on my system, it worked fine once I put the PHP path:
    var PHP_URL:String = "" http://localhost/Vieraskirja.PHP "; "

    Vygo

  • Send table to PHP with HTTPService

    How can I send a picture via HTTPService to a PHP script please?
    If I do this:

    var params: Object = new Objsect();
    params.myData = myDataArray; dataArray is a var table I need to send
    myService.send (params);


    He's not on a table.
    How can I pass the array to PHP?

    You can convert the table to a string in FLEX and PHP, you can use the command "split"...

    Here's example program to see if it helps u

    http://flexarraytransfer.blogspot.com/

  • Working with PHP in Widgets

    Hi, I have just a few questions about PHP with Widgets:

    1. I've read in a few places that you can use PHP in Widgets, but when I tried to include an index.php in my Widget, it notified me that he has not been supported. So I guess I must have my PHP stored on a remote server and bind it using an anchor for example. (Also white list my field).

    If it works, I'm still able to access those Widget API? I have a Javascript with a few Blackberry Menu API file and would like to know if these still work when they are on my remote server.

    2. If I have a remote PHP file and a remote JS file does not work, how I would approach to access a local copy of the JS file that I compiled with the widget?

    I ask these questions because I have a lot of dynamic pages, I'd like to see on my Widget, but would also have the API Widget at hand, as well for menus and other.

    Thank you!

    1. I've read in a few places that you can use PHP in Widgets, but when I tried to include an index.php in my Widget, it notified me that he has not been supported. So I guess I must have my PHP stored on a remote server and bind it using an anchor for example. (Also white list my field).

    Correct... you can not add a PHP page directly in the Archives of your widget.  You can either make it in your widget by white first listing of the URLS in the file config.xml elements and then going to your page via an anchor tag or the definition of the location.href via JavaScript.

    You can also call your PHP via AJAX scripts if you use them to turn the pieces of HTML or data.

    If it works, I'm still able to access those Widget API? I have a Javascript with a few Blackberry Menu API file and would like to know if these still work when they are on my remote server

    Yes, you are still able to access your Widget API from your pages side server.  Each API you wish to access must have its id function declared for the field in the white list.  For example, if your page is located at 'http://www.foo.com' and you want to have access to the API of blackberry.ui.menu... your config.xml element will look like the following:

    http://www.foo.com" subdomains="true">
      
    
    

    This will allow any page that is loaded from the www.foo.com field to access the API JavaScript menu.  This allows you to place the functional parts of your widget where they make sense for your application.

    There is another parameter config.xml that you will be probably interested as well.  You can define your own custom for a BlackBerry Widget header value.  It is thus on your side server PHP code, you can check to make sure that your real widget hitting your PHP script.  The attribute is called "rim: header ' and is located in the root element.  You can consult the Guide to the developer for further details if you are interested.

    2. If I have a remote PHP file and a remote JS file does not work, how I would approach to access a local copy of the JS file that I compiled with the widget?

    Number 1) will work, but you can also do what you ask for (2).  Your PHP page of code on server side, you have white listed and displayed in the widget, has access to your local resources of the widget.  It is quite convenient for common resources that you do not want to draw on the network such as images, css, and JavaScript.

    You can link to these resources by setting their path in your HTML to 'local:///myimage.png '.  The "local: / / /" is a local path that begins at the root of archive widget.  For example if you want to load an image from the local widget it would look like the following:

    
    

    I hope this helps

Maybe you are looking for

  • G6-1b60us: replacement laptop wlan

    The other day, I pointed out that the BIOS of my computer laptop g6-1b60us (product # LW350UA #ABA) has not agreed a new wlan module, even though it was a Ralink 5390, which is among the pieces that are listed as spare parts. He said he needs HP on t

  • Having printing problems

    Hello I have a HP Officejet pro 8500 connected a wireless... As far as I know, everything has been implemented and worked very well. But these days I got trouble I click on print, select 1 copy or never play of what I print... Click OK It says print

  • Scanner of Code information bar appears automatically

    Hi all: I have a problem with a bar code reader, specifically Unitech AS - 10U. Now my problem is this, I am trying to create a sub.vi which accepts the entry of a bar code scanner as if entering the keyboard, make sure that information is the right

  • CVI2010 10.0.1:Combination ListPrealocate, ListCompact and ListDispose cause error

    Hello I rebuild od project of CVI7.1.1 in new CVI 2010 10.0.1 and when run I get the error "NO FATAL RUN - TIME ERROR:...". Attempt to free the pointer to the memory not allocated by malloc() and calloc(). "the line source with function call ListDisp

  • [wired] WRT610N V1 did restart RAS NAT tables?

    Hello: This new unit test, I can see symptoms of the abundance of NAT table after a few days of operation of utorrent P2P, serving 150 torrents. 1 did restart the flush router NAT tables? (Installation - basic configuration - Reboot) 2. What are the