1

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&amp;#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&amp;#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?

0

1 Answer 1

1

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 APPLICATIONs.

$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>";
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.