There are some small questions about running a small program related to xml.

Source: Internet
Author: User
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 ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.