You actually don't need to load the SimpleXML object into that json_encode/decode.
You can use that object already and parse whatever values you needed. Having to encode/decode as an array and to have to access values and then converting it into SimpleXML is too much.
$xml = '<?xml version="1.0"?>
<step number="9">
<s_name>test</s_name>
<b_sel>12345</b_sel>
<b_ind>7</b_ind>
</step>';
$xml = simplexml_load_string(
step = $xml->xpath('//step');
echo $step[0]->attributes()->number; // 9
echo $xml->s_name, '<br/>', $xml->s_name, '<br/>', $xml->b_ind;
Sample Output
With DOMDocument alone:
$dom = new DOMDocument;
$dom->loadXML(
xpath = new DOMXpath($dom);
echo $xpath->evaluate('string(//step/@number)');
Just keep it simple:
$xml = '<?xml version="1.0"?>
<step number="9">
<s_name>test</s_name>
<b_sel>12345</b_sel>
<b_ind>7</b_ind>
</step>';
function convertStepInformationToArray($stepInformation) {
$dom = new DOMDocument();
$dom->loadXML($stepInformation);
$domx = new DOMXPath(
entries = $domx->evaluate("//step");
return $entries;
}
print_r(convertStepInformationToArray($xml));
Answer from Kevin on Stack OverflowPHP
php.net โบ manual โบ en โบ function.xml-parse-into-struct.php
PHP: xml_parse_into_struct - Manual
Example #3 parsemoldb.php - parses moldb.xml into an array of molecular objects
Serialize Object to XML with PHP - PHP - SitePoint Forums | Web Development & Design Community
Hi, I was hoping someone knew of a good XML serializer (not including the Pear one) for PHP. I would like to take an object and serialize it into XML to make a large webservice more maintainable. Any other thoughts on the best way to manage a large xml structure for a webservice are welcome as well. More on sitepoint.com
Unit testing for converting xml file to php classes - Need Help - Cake Software Foundation, Inc.
Hi there, I need help. I convert a xml file to php classes and Iโd like to unit test this task. Thanks More on discourse.cakephp.org
SOAP Response Object Tree from XML String : r/PHPhelp
Generate XML file based on a XSD file.
You can produce a solution by yourself by creating a XSD parser with Dissect , for example, or even JMS Serializer and then create the XML file based on the definition you parsed, using the Faker library while waliking the structure of the schema. I know some old XSD parsers exists in PHP but I don't know where to find them. More on reddit.com
Videos
04:05
PHP XML Parsing Tutorial | SimpleXML Parser Explained for Beginners ...
05:40
PHP SimpleXML Tutorial: Easy XML Parsing for Beginners - YouTube
13:48
How to Parse XML in PHP [Read blog feeds, generate xml sitemap, ...
03:50
How to add simple xml element object as a child to other xml object ...
06:17
How to iterate or loop over an XML object using PHP - YouTube
13:11
How to Parse XML With SimpleXML and PHP - YouTube
Laracasts
laracasts.com โบ discuss โบ channels โบ laravel โบ how-to-xml-data-convert-to-php-object
How to XML data convert to php object
October 14, 2019 - We cannot provide a description for this page right now
W3Schools
w3schools.com โบ php โบ func_simplexml_load_string.asp
PHP simplexml_load_string() Function
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
W3Schools
w3schools.com โบ php โบ php_xml_simplexml_read.asp
PHP SimpleXML Parser
This parser provides an easy way to access elements, attributes and textual content of an XML document. Tip: The SimpleXML Parser is a part of the PHP core.
Envato Tuts+
code.tutsplus.com โบ c โบ coding-fundamentals โบ s โบ xml โบ t โบ tutorials
XML, Coding Fundamentals Tutorials in Code | Envato Tuts+
In this post, you'll learn how to parse XML into an array in PHP.
SitePoint
sitepoint.com โบ blog โบ php โบ parsing xml with simplexml
PHP Master | Parsing XML With SimpleXML
November 7, 2024 - SimpleXML is a PHP extension that allows us to easily manipulate and get XML data. It converts the structure of an XML document into an object that can be processed with normal property selectors and array iterators. This makes it easier to read, parse, and manipulate XML files.
Reddit
reddit.com โบ r โบ PHPhelp โบ comments โบ 1qui1kr โบ soap_response_object_tree_from_xml_string
SOAP Response Object Tree from XML String : r/PHPhelp
We cannot provide a description for this page right now
PHPBuilder
board.phpbuilder.com โบ d โบ 10381187-mapping-xml-to-object
Mapping XML to Object - PHPBuilder Forums
September 2, 2011 - Does anyone know of a tool, script some of that nature that will map a multi-level XML file to a custom object? Using SimpleXML I can get a StdObject, but ne...