Solved

PHP + domdocument + start line expected. <

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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

15 Experts available now in Live!

Get 1:1 Help Now