Xml learning notes

Source: Internet
Author: User

Xml learning notes

<? Php $ textTpl = '<xml> <Content> <! [CDATA [% s]> </Content> <news> <! [CDATA [% s]> </news> <FuncFlag> <! [CDATA [% s]> </FuncFlag> <body> <! [CDATA [addcon]> </body> </xml> '; // $ xmlobj = SimpleXML () $ postObj = simplexml_load_string ($ textTpl, 'simplexmlelement', LIBXML_NOCDATA ); // load xml and encapsulate xml into an object echo $ postObj-> Content; // obtain the value of the xml Element $ postObj-> body [0]-> addChild ("date ", "2016-01-01"); // Add a subnode foreach ($ postObj-> body-> children () as $ child) {echo "Child node :". $ child; // output the newly added child node} // or use echo $ postObj-> body-> date; to directly output // assign values to xml elements

$ String = "decimal: % s, floating point: % f, string: % s"; $ number = "123"; $ fnumber = "123.123 "; $ str = "qwee1231wqaqe3q"; $ txt = sprintf ($ string, $ number, $ fnumber, $ str); // sprintf dial percentage (%) replace the symbol with the variable % s % f passed as the parameter to be replaced with the variable/* sprintf data format %-return a percent sign % B-Binary Number % the character % d corresponding to the c-ASCII value contains the decimal number of plus and minus signs (negative, 0, positive) % e-use lower-case scientific notation (e.g. 1.2e + 2) % E-use upper-case scientific notation (e.g. 1.2E + 2) % u-decimal number (greater than or equal to 0) % f-floating point number (local) % F-floating point number (non-local) % g-shorter % e and % f % G-shorter % E and % f % o-octal digits % s-string % x-hexadecimal digits (lowercase letters) % X-hexadecimal number (uppercase letter */$ outstr = sprintf ($ textTpl, $ number, $ str, $ fnumber ); // put the variable into xml $ postObj = simplexml_load_string ($ outstr, 'simplexmlelement', LIBXML_NOCDATA); // load xmlecho $ outstr; // output the entire xml file echo $ postObj-> FuncFlag; // obtain the value in 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.