PHP generation XML solution

Source: Internet
Author: User
PHP generates XML. I use this code to generate xml & lt ;? Php & nbsp; include ("conn/conn. php "); & nbsp; $ path & nbsp; = & nbsp; 'XML/createxml. xml '; & nbsp; if (file_exists ($ path) & nbsp; unl PHP generates XML
I use this code to generate xml
Include ("conn/conn. php ");
$ Path = 'XML/createxml. XML ';
If (file_exists ($ path) unlink ($ path );
$ Handle = fopen ($ path, 'w ');
$ XmlContent. =' ';
$ XmlContent. =' ';
// Query all sections
$ Select1 = $ _ POST ['select1'];
$ Select2 = $ _ POST ['select2'];
Echo $ select1;
Echo $ select2;
$ Query = "select * from tb_car where car_road like '% $ select1 %' and car_road like '% $ select2 % '";
$ Result = mysql_query ($ query );
If (mysql_num_rows ($ result)> 0 ){
While ($ myrow = mysql_fetch_array ($ result )){
$ XmlContent. =' ';
$ XmlContent. =' ';
$ XmlContent. =' ';
$ XmlContent. =' ';
$ XmlContent. =' ';
}
}
$ XmlContent. ='';
If ($ handle)
{
If (fwrite ($ handle, $ xmlContent ))
{
Fclose ($ handle );
}
Echo "script window. location. href = 'indexs. php? Lmbs = car source information query & select1 = $ select1 & select2 = $ select2 '; script ";
}
?>

----
Why is the location of the generated xml data and value changed?

-
-




-




-





------ Solution --------------------
Xml generation is like this. you can write dtd file constraints.
------ Solution --------------------
$ XmlContent. ='';
Echo $ xmlContent; exit (); try
------ Solution --------------------
Reference:
Xml generation is like this. you can write dtd file constraints.

Can the order of attributes be defined ?? How should I fix it ??
------ Solution --------------------
Http://www.w3school.com.cn/dtd/index.asp
------ Solution --------------------



Hello, I just read your code and the results are quite strange.


I noticed the sixth line of your code: $ xmlContent. =' ';

I found that your variable is neither defined nor assigned a value. you should remove the Connector "." and you should remove it for testing.


Bytes -------------------------------------------------------------------------------------------------------------------

I remember that the xml dtd (Document Type Definition) can standardize the order of definition, but it can only specify the order of elements. As for the order of attributes, I just tested it, it seems useless, but I wrote a DTD for you. you can try it.











]>

……





Bytes -------------------------------------------------------------------------------------------------------------------

If you want to get rid of it, you can also try the DOMDocument () class that specifically operates XML.





Try it. I hope it will be useful to you.

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.