You can also see C++, C, Js, or Java repository.
To check if you have a compatible version of Php installed, use the following command:
php -V
You can find the latest version of Php here.
Install the latest version of Git.
In order to work on code, create a fork from GitHub page. Use Git for cloning the code to your local or below line for Ubuntu:
git clone <your-fork-git-link>
A directory called XmlParser will be created. Or you can use below link for exploring the code:
git clone https://github.com/starlangsoftware/XmlParser-Php.git
Steps for opening the cloned project:
- Start IDE
- Select File | Open from main menu
- Choose
XmlParser-Php
file - Select open as project option
- Couple of seconds, dependencies will be downloaded.
In order to load an xml document, we use the constructor
$doc = new XmlDocument($fileName)
and parse with the parse method
$doc->parse()
Root node of the document can be obtained via the getFirstChild method:
$rootNode = $doc->getFirstChild()
For example, to iterate over the first level tags in the xml file one can use
$rootNode = $doc->getFirstChild()
$childNode = $rootNode->getFirstChild()
while ($childNode){
...
$childNode = $childNode->getNextSibling()
}
Tag name can be obtained via getName, pcData via getPcData methods.