Solved

PHP + domdocument + start line expected. <

Posted on 2007-11-16
5
650 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:sreejith_y
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20303855
is there a reason for creating this twice?
            $doc = new DOMDocument('1.0');
            $doc = new DOMDocument;
try dropping the first one
0
 

Author Comment

by:sreejith_y
ID: 20304081

I have tried both seperately.. But same error is coming..
0
 
LVL 3

Accepted Solution

by:
pmctrek earned 75 total points
ID: 20318929
You are forgetting that XML is a tree type structure you need to start the XML tree with

$doc->appendChild($doc->createElement('root'));

But do remove the second assignment
$doc = new DOMDocument;
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question