Some minor issues occurred when running a small program related to xml. & lt ;? & Nbsp; $ conn & nbsp ;=& nbsp; mysql_connect ('localhost', & nbsp; 'root', & nbsp; '') & nbsp; or & nbsp; die ('Could & nbsp; not & nbsp; connect: & nbsp; '& nbsp ;. some minor issues occurred when running a small xml-related program.
$ Conn = mysql_connect ('localhost', 'root', '') or die ('could not connect: '. mysql_error ());
Mysql_select_db ('ggn ', $ conn) or die ('Can \' t use database: '. mysql_error ());
$ Str = "SELECT id, username FROM 'htx _ admin' group by 'id' order by 'id' ASC ";
$ Result = mysql_query ($ str) or die ("Invalid query:". mysql_error ());
If ($ result)
{
$ XmlDoc = new DOMDocument ();
If (! File_exists ("01.xml ")){
$ Xmlstr =" ";
$ XmlDoc-> loadXML ($ xmlstr );
$ XmlDoc-> save ("01.xml ");
}
Else {$ xmlDoc-> load ("01.xml ");}
$ Root = $ xmlDoc-> documentElement;
While ($ arr = mysql_fetch_array ($ result )){
$ Node1 = $ xmlDoc-> createElement ("id ");
$ Text = $ xmlDoc-> createTextNode (iconv ("GB2312", "UTF-8", $ arr ["id"]);
$ Node1-> appendChild ($ text );
$ Node2 = $ xmlDoc-> createElement ("name ");
$ Text2 = $ xmlDoc-> createTextNode (iconv ("GB2312", "UTF-8", $ arr ["username"]);
$ Node2-> appendChild ($ text2 );
$ Root-> appendChild ($ node1 );
$ Root-> appendChild ($ node2 );
$ XmlDoc-> save ("01.xml ");
}
}
Mysql_close ($ conn );
?>
The error message displayed on the webpage is as follows:
The XML page cannot be displayed.
You cannot view XML input using a style sheet. Correct the error and click refresh or try again later.
The XML document must have a top-level element. An error occurred while processing the resource 'http: // localhost/ggn/test/lookxml. php.
What are these errors? why is my php. ini xml not configured.
------ Best solution --------------------
$ XmlDoc-> save ("01.xml ");
Is saved to file 01.xml
Instead of outputting data to a browser
------ Other solutions --------------------
Is this all code?
Since you have not output any data, how can the browser interpret it as XML?
------ Other solutions --------------------
Reference:
Is this all code?
Since you have not output any data, how can the browser interpret it as XML?
This is all the code. Isn't this statement output? $ xmlDoc-> save ("01.xml ");