Creating an XML string from php string

Lovelock

Looking to parse some XML data that is saved in a DB. In the DB its saved in raw XML:

<?xml version="1.0" encoding="utf-8"?>
  <RESPONSE>
    <SUCCESS>true</SUCCESS>
    <ERRORMESSAGE>
    </ERRORMESSAGE>
    <DATA>
    </DATA>
 </RESPONSE>

I want to be able to parse this data, and have found people normally using:

$xmlstr = <<<XML RAW XML XML;

But how can I use a php string in there?

So e.g.

$xmlstr = <<<XML $stringfromDB XML;

Of course that does not work, but how can it be done? Thanks.

yergo

SimpleXML should do the trick for you. Check out this link, along with php manual basics.

$xmlData = /* query xml-data from DB as string */;
$xmlObj = simplexml_load_string($xmlData);
var_dump($xmlObj);

the <<<XML ...some code... XML; is just an alternative notation for declaring (multiline) strings, you don't have to do that, as long as you can obtain full XML document from DB as in your first snippet.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating XML string with multiple items in PHP

From Dev

creating xml string from java data structures

From Dev

Trouble creating a PHP string

From Dev

Creating a string from chars

From Dev

Creating an entity from String

From Dev

Creating a string from a path

From Dev

Creating xml node from Unicode string (encoding declaration not supported)?

From Dev

Creating xml node from Unicode string (encoding declaration not supported)?

From Dev

Php Fetch the value from this XML string

From Dev

Php Fetch the value from this XML string

From Dev

Getting values from an XML string in PHP

From Dev

Removing the <br /> tags from an XML string in PHP

From Dev

PHP: get data from XML string

From Dev

PHP - Creating an array from a string given from an API

From Dev

Creating a webservice that accepts XML as a string

From Dev

Creating a PDO connection string from PHP class and DBMS techniques

From Dev

php algorithm for creating a list of keywords from a string of keywords

From Dev

php algorithm for creating a list of keywords from a string of keywords

From Dev

PHP - Converting XML to array misses some information from XML string

From Dev

php prevent & creating codes in a string

From Dev

Reading XML String In PHP

From Dev

decode xml string in php

From Dev

Creating string array from a delimited string.

From Dev

Creating a UUID from a string with no dashes

From Dev

creating Hashmap from a JSON String

From Dev

Regex for creating an array from String

From Dev

Creating a string from Vec<char>

From Dev

Creating String Array from CSV

From Dev

Creating variables from string names