---
title: "How to read xml file in PHP"  
description: "How to read xml file in PHP"  
author: "Manoj Bhatt"  
published: 2011-11-30  
updated: 2011-12-01  
canonical: https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# How to read xml file in PHP

Hi Guys,

Can [someone tell me](https://www.mindstick.com/forum/34097/can-someone-tell-me-what-is-the-most-effective-optimization-on-page-optimization-or-off-page-optimization), how to read [xml file](https://www.mindstick.com/forum/30/read-xml-file-data-in-c-sharp) in [php](https://www.mindstick.com/articles/12149/php-constant-and-php-variables)?

Thanks

## Replies

### Reply by Anonymous User

Hi Manoj Bhatt,\
To read [XML](https://www.mindstick.com/blog/203/working-with-xml-data-in-sql-server) [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) in PHP, you can use the following code:\

```
 // Create DOMDocument object           $xmlDoc = new DOMDocument();// load XML file            $xmlDoc->load("YourFile.xml");            $ptag = $xmlDoc->getElementsByTagName('ParentNode');            $childQType=$ptag->item($i)->getElementsByTagName('ChildNode');            echo $childQType->item(0)->childNodes->item(0)->nodeValue;  
```

So in the same manner you can get all nodes values.


---

Original Source: https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
