Solved

PHP + domdocument + start line expected. <

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 35
Dynamic varibles 5 32
How to populate a dynamically created text input from ajax return 18 43
XSLT Display Label Name 1 22
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

808 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