Reputation: 111
I have an XML file and i want to print the data as html which contains multiple tags. I have looped the file using foreach but it only prints the tags of the XML file. The text inside the tags are not printing.
This is my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<Jobs>
<APPLICATION>
<ACTION><![CDATA[MODIFY]]></ACTION>
<JOBID><![CDATA[21494017]]></JOBID>
<JOBTITLE><![CDATA[dummy MNC&#x27;S of Pune.]]></JOBTITLE>
<JobDescription><![CDATA[dummy]]></JobDescription>
<KEYSKILLS><![CDATA[dummy]]></KEYSKILLS>
<SUMMARY><![CDATA[dummy]]></SUMMARY>
</APPLICATION>
<APPLICATION>
<ACTION><![CDATA[MODIFY]]></ACTION>
<JOBID><![CDATA[21494017]]></JOBID>
<JOBTITLE><![CDATA[dummy MNC&#x27;S of Pune.]]></JOBTITLE>
<JobDescription><![CDATA[dummy]]></JobDescription>
<KEYSKILLS><![CDATA[dummy]]></KEYSKILLS>
<SUMMARY><![CDATA[dummy]]></SUMMARY>
</APPLICATION>
AND SO ON..........................................
</Jobs>
The issue i am facing is that when i loop it only print the tags like:
Jobs
APPLICATION:
APPLICATION:
APPLICATION:
APPLICATION:
APPLICATION:
Following is the code that i am using to print the XML file:
$xml=simplexml_load_file("fli.xml");
echo $xml->getName() . "<br>";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br>";
}
I am not able to print the data inside the APPLICATION
. How do I do it?
Upvotes: 1
Views: 84
Reputation: 27139
The APPLICATION
element doesn't contain text. You should do one more inner cycle on $child
to get the text inside the inner tags. At the moment you're just cycling on the APPLICATION
s.
$xml=simplexml_load_file("fli.xml");
echo $xml->getName() . "<br>";
foreach($xml->children() as $child)
{
foreach($child->children() as $inner) {
echo $inner->getName() . ": " . $inner. "<br>";
}
}
Upvotes: 1