---
title: "How to Create SimpleXMLElement Object in Magento 2"
url: "https://magecomp.com/blog/create-simplexmlelement-object-magento-2/"
date: "2017-12-04T11:25:06+00:00"
modified: "2025-02-22T06:43:33+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 193
reading_time: "1 min read"
summary: "Working with Development &amp; customization in Magento 2, every day we get something fresh challenges from our clients that we love to accept. Nowadays, e-Commerce Store owners are in a hunt for t..."
description: "Follow this complete guide step by step guide for creating simple XML element object in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to get the Current Date using Custom Format in Magento 2"
    url: "https://magecomp.com/blog/get-the-current-date-using-custom-format-in-magento-2/"
  - title: "Top 5 Best CDN Providers for Magento 2 "
    url: "https://magecomp.com/blog/cdn-providers-magento-2/"
  - title: "How to write a Delete SQL query using Standard way without Model File in Magento 2"
    url: "https://magecomp.com/blog/write-delete-sql-query-using-standard-way-without-model-file-magento-2/"
---

# How to Create SimpleXMLElement Object in Magento 2

_Published: December 4, 2017_  
_Author: Dhiren Vasoya_  

![img how to create simple XMLElement Object in Magento 2](https://magecomp.com/blog/wp-content/uploads/2017/12/img_how-to-create-simple-XMLElement-Object-in-Magento-2-1024x332.webp)

Working with Development & customization in Magento 2, every day we get something fresh challenges from our clients that we love to accept. Nowadays, e-Commerce Store owners are in a hunt for that one thing which delivers great shopping experience and secure transactions which Magento provides. One of our Clients also came with the requirement in which he wants to parse the XML response in Magento 2. As of now, it’s not allowed to parse data directly, so we have found one simple trick which we would like to share with our readers.

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

```
  $ch = curl_init();

  $sendurl = "http://example.com";
  curl_setopt($ch, CURLOPT_URL, $sendurl);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $data = curl_exec($ch);
  curl_close($ch);

  $response = preg_replace("/(</?)(w+):([^>]*>)/", "$1$2$3", $data);
  $xml = new SimpleXMLElement($data);
```

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-5.webp)](https://magecomp.com/magento-malware-removal.html)

To parse XML data, we have to use \SimpleXMLElement to define object of Simple XML Element. Now you know to create XML to parse data, you can improve your skills by parsing different XML feeds from various APIs. Comment down below if you face any issue while parsing data and stay tuned for more tips & tricks.

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)
**Happy Parsing!**


---

_View the original post at: [https://magecomp.com/blog/create-simplexmlelement-object-magento-2/](https://magecomp.com/blog/create-simplexmlelement-object-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-14 23:56:09 UTC_  
