php½âÎöxmlʾÀý
<!-- xml ¸ñʽ
<books>
<book id='1001'>
<author>andylin</author>
<title>c language</title>
<publisher id="aaa">O'Reilly</publisher>
</book>
<book id='1002'>
<author>congfeng</author>
<title>C++ Designer</title>
<publisher id='bbb'>New Publish</publisher>
</book>
</books>
-->
<?php
$dom = new DOMDocument();
if (!$dom->load('books.xml'))
{
echo "load books.xml failed!<br>";
return;
}
$books = $dom->getElementsByTagName('book');
foreach ($books as $book)
{
//get book id
$book_id = $book->getAttribute('id');
//get author
$nodeAuth = $book->getElementsByTagName('author');
$strAuth = $nodeAuth->item(0)->nodeValue;
//get publisher
$nodePub = $book->getElementsByTagName('publisher');
$strPub = $nodePub->item(0)->nodeValue;
$pub_id = $nodePub->item(0)->getAttribute('id');
//get title
$nodeTitle = $book->getElementsByTagName('title');
$strTitle = $nodeTitle->item(0)->nodeValue;
//save data
$arrInfo['book_id'] = $book_id;
$arrInfo['author'] = $strAuth;
$arrInfo['publiser'] = $strPub;
$arrInfo['title'] = $strTitle;
$arrInfo['pub_id'] = $pub_id;
//save info
$arrInfos[] = $arrInfo;
}
var_dump($arrInfos);
?>
Ïà¹ØÎĵµ£º
printf()º¯ÊýÊǸñʽ»¯Êä³öº¯Êý, Ò»°ãÓÃÓÚÏò±ê×¼Êä³öÉ豸°´¹æ¶¨¸ñʽÊä³öÐÅÏ¢¡£ÔÚ±àд³ÌÐòʱ¾³£»áÓõ½´Ëº¯Êý¡£º¯ÊýµÄÔÐÍΪ£º
int printf(string $fromat [,mixed $args [,mixed ...]])
º¯Êý·µ»ØÖµÎªÕûÐÍ¡£Èô³É¹¦Ôò·µ»ØÊä³öµÄ×Ö·ûÊý£¬Êä³ö³ö´íÔò·µ»Ø¸ºÖµ¡£
printf()º¯ÊýµÄµ÷ÓøñʽΪ:
printf("<¸ñʽ»¯×Ö·û´®>", & ......
public string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
writer = new XmlTextWriter(stream, Encoding.Default);
......
Ò»¡¢ÒýÂÛ
PHP,Ò»ÃÅ×î½ü¼¸ÄêÐËÆðµÄwebÉè¼Æ½Å±¾ÓïÑÔ,ÓÉÓÚËüµÄÇ¿´óºÍ¿ÉÉìËõÐÔ,½ü¼¸ÄêÀ´µÃµ½³¤×ãµÄ·¢Õ¹,phpÏà±È´«Í³µÄaspÍøÕ¾,ÔÚËÙ¶ÈÉÏÓоø¶ÔµÄÓÅÊÆ,Ïëmssqlת6ÍòÌõÊý¾ÝphpÈçÐèÒª40Ãë,asp²»ÏÂ2·ÖÖÓ.µ«ÊÇ,ÓÉÓÚÍøÕ¾µÄÊý¾ÝÔ½À´Ô½¶à,ÎÒÃÇ¿ÊÇóÄܸü¿ìËٵĵ÷ÓÃÊý¾Ý,²»±ØÒªÃ¿´Î¶¼´ÓÊý¾Ý¿âµô,ÎÒÃÇ¿ÉÒÔ´ÓÆäËûµÄµØ·½,±È·½Ò»¸öÎļþ,»òÕßij¸ ......
×î½üÔÚѧϰphp£¬Ò³ÃæÒѾ×öºÃÁË£¬ÏÖÔÚ¾ÍÊǺÍÐéÄâ»úÀïC´úÂëµÄͨÐÅ£¬socket±à³Ì»¹¿ÉÒÔ£¬¾ÍÊÇÄÃÊý¾ÝµÄ´¦Àí£¬ÄÑ£¬¡£
ÀàµÄ±à³ÌÎÒ²»»á£¬Ã»ÓÐѧ¹ýC++¡£±¾À´´òËãÓýṹÌåµÄ£¬¿ÉÊÇPHPÀïÃæ¾ÓȻûÓнṹÌ壬Ôõô°ìÄØ£¿¼ÌÐøÅ¬Á¦°É
......
<!-- xml¸ñʽ
<foo xmlns="test">
<bar attr='a'></bar>
<bar attr='b'></bar>
<bar attr='c'></bar>
</foo>
-->
<?php
$dom = new DOMDocument();
if (!$dom->load('attr.xml'))
{
echo "load books.xml failed!<br>";
re ......