Solved

PHP + domdocument + start line expected. <

Posted on 2007-11-16
5
646 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now