• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 661
  • Last Modified:

PHP + domdocument + start line expected. <

HI All,

Following is my code for generating an xml with employee details. I am using PHP 5.2.1

      $result = mysql_query ("select * from tblemployee" ) ;
      if (mysql_num_rows($result) != 0)
            $doc = new DOMDocument('1.0');
            $doc = new DOMDocument;
            $doc->formatOutput = true;
            $videolibrary = $doc->createElement("EmpGroup");
            $videolibrary = $doc->appendChild($videolibrary);
            while ($row = mysql_fetch_array($result))
                  $video = $doc->createElement("Group");
                  $video->setAttribute("grp_name" , $row['Emp_Grp']);
                  $video = $videolibrary->appendChild($video);                  
            $xml_string = htmlentities($doc->saveXML());
            echo ("&status=success&output=$xml_string&");

But the script is giving following error.

domdocument - start tag expected <

Please help me.

Thanks in Advance
1 Solution
is there a reason for creating this twice?
            $doc = new DOMDocument('1.0');
            $doc = new DOMDocument;
try dropping the first one
sreejith_yAuthor Commented:

I have tried both seperately.. But same error is coming..
You are forgetting that XML is a tree type structure you need to start the XML tree with


But do remove the second assignment
$doc = new DOMDocument;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now