http://trash.chregu.tv/phpconf2003/examples/
PHP5µÄXMLÐÂÌØÐÔ
×÷Õß Christian Stocker Òe ice_berg16(Ñ°Ãεĵ¾²ÝÈË)
ÃaeÏoµÄ¶ÁÕß
ÕaƪÎÄÕµÄÃaeÏo¶ÔÏoÊÇËuÓжÔPHP5µÄXMLй¦ÄܸÐÐËȤµÄ¸÷¸oˮƽµÄPHP¿ª¢Õß¡£ÎÒÃǼٶ¨¶ÁÕßÕÆÎÕXMLµÄ»u±¾ÖªÊ¶¡£È»¶ø£¬Èç¹uÄaÒѾÔÚÄaµÄPHPµ±ÖÐʹÓÃÁËXML£¬ÄÇôÕaƪÎÄÕÂÒ²»aÈÃÄaÊÜÒaeÇdz¡£
½eÉÜ
ÔÚµ±½ñµÄ»¥ÁªÍøÊÀ½ç£¬XMLÒѾ²»ÔÙÊÇÒ»¸oʱ÷Ö´ÊÁË£¬ËuÒѾ±»¹aºµÄ½ÓÊܺ͹ae¶µÄʹÓÃÁË¡£Òo´ËÏa¶ÔÓÚPHP4£¬PHP5¶ÔÓÚXMLµÄÖ§³Ö¸uÊܵ½ÁËÖØÊÓ¡£ÔÚPHP4ÖÐÄaÃae¶ÔµÄ¼¸ºo¶¼ÊÇDZe×¼£¬APIÖжϣ¬ÄÚ´aeйÂ(C)ÒÔ¼°ÆaËu²»ÍeÈ«µÄ¹¦ÄÜ¡£¾¡¹ÜÓÐÐ(C)²»×aÒѾÔÚPHP4.3Öеõ½¸Ä½ø£¬¿ª¢ÕßÃÇ»¹ÊǾo¶¨Å×ÆuÔÓеĴuÂe£¬ÔÚPHP5ÖØдȫ²¿´uÂe¡£
ÕaƪÎÄÕ½«¶ÔPHP5ÖйØÓÚXMLµÄËuÓÐÁiÈ˼¤¶¯µÄÐÂÌØÐÔÖðÒ»½eÉÜ¡£
PHP4 µÄ XML
ÔçÆÚµÄPHP°ae±¾¾ÍÒѾ¿ªÊ¼Ö§³ÖXMLÁË£¬¶øÕaÖ»ÊÇÒ»¸o»uÓÚSAXµÄ½Ó¿Ú£¬Ëu¿ÉÒÔÇaËɵĽaÎoÈκÎXMLÎĵµ¡£Ëae×ÅPHP4ÖмÓÈeÁËDOMXMLÀ(C)չģ¿e£¬XML±»¸uºÃµÄÖ§³ÖÁË¡£ºoÀ´XSLT×oΪ²¹³a±»¼ÓÁ˽øÀ´¡£ÔÚÕu¸oPHP4µÄ½×¶Î£¬ÆaËuÒ»Ð(C)¹¦ÄÜÈçHTML£¬XSLTºÍDTDÑeÖ¤Ò²±»¼Óµ½ÁËDOMXMLÀ(C)Õ¹ÖУ¬²»ÐÒµÄÊÇ£¬ÓÉÓÚXSLTºÍDOMXMLÀ(C)չʼÖÕ´¦ÓÚʵÑe½×¶Î£¬API²¿ÖÒ²±»²»Ö¹Ò»´ÎµÄÐ޸ģ¬ËuÃÇ»¹ÊDz»ÄÜÒÔĬÈϽʽ°²×°¡£´ËÍa£¬DOMXMLÀ(C)չûÓÐ×ñÑW3CÖƶ¨µÄDOM±e×¼£¬¶øÓÐ×Ô¼ºµÄÃuÃu½¨¡£ËaÈ»ÔÚPHP4.3ÖÐÕa²¿ÖµÃµ½Á˸ÄÉƲ¢ÇÒÐi¶aÄÚ´aeйÂ(C)ºÍÆaËuÒ»Ð(C)¹¦ÄÜÒ²µÃÒÔÐÞ¸´£¬µ«ËuʼÖÕûÓТչµ½Ò»¸oÎȶ¨µÄ½×¶Î£¬Ò»Ð(C)ÉiÈeµÄÎÊÌaÒѾ¼¸ºo²»¿ÉÄÜÐÞ¸´¡£Ö»ÓÐSAXÀ(C)Õ¹±»ÒÑĬÈϽʽ°²×°£¬ÆaËuµÄÒ»Ð(C)À(C)Õ¹´ÓδµÃµ½¹aºµÄʹÓá£
»uÓÚËuÓÐÕaÐ(C)ÔÒo£¬PHPµÄXML¿ª¢Õß¾o¶¨ÔÚPHP5ÖØдȫ²¿´uÂe£¬²¢×ñÑʹÓñe×¼¡£
PHP5µÄXML
ÔÚPHP5ÖÐËuÓÐÖ§³ÖXMLµÄ²¿Ö¼¸ºoÈ«²¿ÖØбaд.ÏÖÔÚµÄËuÓÐXMLÀ(C)Õ¹¶¼ÊÇ»uÓÚGNOMEÏiÄ¿µÄLIBXML2¿a¡£Õa½«ÔÊÐiÔÚ²»Í¬µÄÀ(C)չģ¿eÖ®¼a»¥Ïa²Ù×÷£¬ºËÐÄ¿ª¢ÕßÖ»ÐeÒªÔÚÒ»¸oµ×²aµÄ¿aÉϽøÐпª¢¡£ÀýÈ磬¸´ÔÓµÄÄÚ´ae¹ÜÀiֻʵÏÖÒ»´Î¾Í¿ÉÒÔÈÃËuÓÐXMLÏa¹ØÀ(C)Õ¹µÃµ½¸ÄÉÆ¡£
³ýÁ˼̳ÐPHP4ÖÐÎÅÃuµÄSAX½aÎoÆ÷Ö®Ía£¬PHP5»¹Ö§³Ö×ñÑW3C±e×¼µÄDOMºÍ»uÓÚLIBXSLTÒýÇaeµÄXSLT¡£Í¬Ê±»¹¼ÓÈeÁËPHP¶ÀÓеÄSimpleXMLÀ(C)Õ¹ºÍuºÏ±e×¼µÄSOAPÀ(C)Õ¹¡£Ëae×ÅXMLÔ½À´Ô½±»ÖØÊÓ£¬PHP¿ª¢Õß¾o¶¨ÔÚĬÈÏ°²×°½Ê½ÖмÓÈe¸u¶a¶ÔXMLµÄÖ§³Ö¡£Õa¾ÍÒaζ×ÅÄaÏÖÔÚ¿ÉÒÔʹÓÃSAX£¬DOMºÍSimpleXML£¬¶øÕaÐ(C)À(C)Õ¹½«»aÔÚ¸u¶aµÄþÎñÆ÷ÉÏ°²×°¡£È»ºo¶ÔÓÚXSLTºÍSOAPµÄÖ§³Ö£¬»¹ÐeÒªÔÚPHP±aÒeʱ±»ÏÔʽµÄÅaÖá£
Êý¾ÝÁ÷µÄÖ§³Ö
ÏÖÔÚËuÓеÄXMLÀ(C)Õ¹¶¼Ö§³ÖPHPÊý¾ÝÁ÷£¬¼´Ê¹Äa²»´ÓPHPÖÐÖ±½ÓÃÎÊ¡£ÀýÈ磬ÔÚPHP5ÖÐÄa¿ÉÒÔ´ÓÒ»¸oÎļþ»o´ÓÒ»ÌoÖ¸ÁiÃÎÊÊý¾ÝÁ÷¡£»u±¾ÉÏÄaÄܹ»ÔÚÈκοÉÒÔÃÎÊÆÕͨÎļþµÄµØ½ÃÎÊPHPÊý¾ÝÁ÷¡£
PHP4.3ÖмoÒªµÄ½eÉÜÁËÊý¾ÝÁ÷£¬ÔÚPHP5ÖÐÒѾµÃµ½Á˽øÒ»²½µÄÌa¸ß£¬°uº¬Îļþ´aeÈ¡£¬ÍøÂç´aeÈ¡ºÍÆaËu²Ù×÷£¬Èç¹²ÏiÒ»Ì×¹¦Äܺ¯Êý¡£ÄaÉoÖÁ¿ÉÒÔʹÓÃPHP´uÂeÀ´ÊµÏÖÄa×Ô¼ºµÄÊý¾ÝÁ÷£¬ÕaÑuÊý¾Ý´aeÈ¡½«±aµÃdz£¼oµ¥¡£¹ØÓÚÕa²¿ÖµÄ¸u¶aϸ½ÚÇe²Î¿¼PHPÎĵµ¡£
SAX
SAXµÄÈ«³ÆÊÇSimple API for XML£¬ËuÊÇÓÃÓÚ½aÎoXMLÎĵµµÄ½Ó¿Ú£¬ÊÇ»uÓڻص÷ÐÎʽµÄ¡£´ÓPHP3¿ªÊ¼¾ÍÒѾ֧³ÖÁËSAX£¬µ½ÏÖÔÚҲûÓÐÌ«´oµÄ±a»¯¡£ÔÚPHP5ÖУ¬API½Ó¿Ú²¢Ã»Óиıa£¬ËuÒÔÄaµÄ´uÂeÈÔÈ»¿ÉÒÔÔËÐС£Î¨Ò»²»Í¬µÄÊÇËu²»ÔÙ»uÓÚEXPAT¿a£¬¶øÊÇ»uÓÚLIBXML2¿a¡£
Õa¸o±a»¯´øÀ´ÁËÒ»Ð(C)¶ÔÃuÃu¿Õ¼aÖ§³ÖÉϵÄÎÊÌa£¬Õa¸oÎÊÌaÔÚLIBXML2.2.6°ae±¾ÖÐÒѾµÃµ½½a¾o¡£µ«ÊÇLIBXML2ÒÔÇ°µÄ°ae±¾Öв¢Ã»Óнa¾o£¬Òo´ËÈç¹uÄaʹÓÃÁËxml_parse_create_ns()£»Ç¿ÁÒ½¨ÒeÔÚÄaµÄϵͳÉÏ°²×°LIBXML2.2.6¡£
DOM
DOM (Îĵµ¶ÔÏoÄ£ÐÍ)ÊÇÓÉW3CÖƶ¨µÄÒ»Ì×ÃÎÊXMLÎĵµÊ÷µÄ±e×¼¡£ÔÚPHP4¿ÉÒÔʹÓÃDOMXMLÀ´¶Ô´Ë½øÐвÙ×÷£¬DOMXMLµÄ×iÖ÷ÒªÎÊÌaÊÇËu²»uºÏ±e×¼µÄÃuÃu½¨¡£¶øÇÒÔںܳ¤Ò»¶Îʱ¼aÄÚ»¹´aeÔÚÄÚ´aeйÂ(C)ÎÊÌa£¨PHP4.3ÒѾÐÞ¸´ÁËÕa¸oÎÊÌa£(C)¡£
еÄDOMÀ(C)Õ¹ÊÇ»uÓÚW3C±e×¼Íe³ÉµÄ£¬°uº¬½¨ºÍÊoÐÔÃu³Æ¡£Èç¹uÄaÔÚÆaËuÓiÑÔÖÐÊiϤDOM£¬ÀýÈçÔÚJavascriptÖУ¬ÄÇôÔÚPHPÖбaдÀaËƵŦÄܽ«±aµÃdz£ÈÝÒס£Äa²»±Øÿ´Î¶¼²e¿´Îĵµ£¬ÒoΪ½¨ºÍ²ÎÊý¶¼ÊÇÏaͬµÄ¡£
ÓÉÓÚʹÓÃÁËеÄW3C±e×¼£¬»uÓÚDOMXMLµÄ´uÂe½«²»ÄÜÔËÐС£ÔÚPHPÖеÄAPIÓкܴoµÄ²»Í¬¡£µ«ÊÇÈç¹uÄaµÄ´uÂeÖÐʹÓÃÁËÀaËÆW3C±e×¼µÄ½¨ÃuÃu½Ê½£¬ÒÆÖ²²¢²»ÊǺÜÀ§ÄÑ¡£ÄaÖ»ÐeÒª½«ÔØÈeº¯ÊýºÍ±£´aeº¯ÊýÐ޸ģ¬É¾³ýº¯ÊýÃuÖеÄÏ»®Ïߣ¨DOM±e׼ʹÓÃÊ××Öĸ´oд£(C)¡£ÆaËu¸÷´¦µÄµ÷½Úµ±È»Ò²ÊDZØÐeµÄ£¬µ«ÊÇÖ÷ÒªÂß¼²¿Ö¿ÉÒÔ±£³Ö²»±a¡£
¶ÁÈ¡DOM
ÎÒ²»»aÔÚÕaƪÎÄÕÂÖнaÊÍDOMÀ(C)Õ¹µÄËuÓÐÌØÐÔ£¬ÄÇÒ²ÊÇûÓбØÒªµÄ¡£»oÐiÄaÓ¦¸Ã½«HTTP://www.w3.org/DOMµÄÎĵµ¼ÓÈeÊeÇ(C)...¿Ö»u±¾ÉÏÏaͬ¡?/a>
ÔÚÕaƪÎÄÕµĴo¶aÊýÀý×ÓÖÐÎÒÃǽ«Ê¹ÓÃͬһ¸oXMLÎļþ£¬zend.comÉÏÓÐdz£¼oµ¥µÄRSS°ae±¾¡£½«ÏÂÃaeµÄÎı¾Õ³Ìuµ½Ò»¸oÎı¾ÎļþÖв¢±£´aeΪarticles.xml¡£
http://www.zend.com/zend/week/week172.php
http://www.zend.com/zend/tut/tut-hatwar3.php
Òª½«Õa¸oÀý×ÓÔØÈeµ½Ò»¸oDOM¶ÔÏo£¬Ê×ÏÈÒª´´½¨Ò»¸oDOMDocument¶ÔÏo£¬È»ºoÔØÈeXMLÎļþ¡£
$dom = new DomDocument();
$dom->load("articles.xml");
ÕýÏñÉÏÃaeËuÌa¼°µÄ£¬Äa¿ÉÒÔʹÓÃPHPµÄÊý¾ÝÁ÷À´ÔØÈeÒ»¸oXMLÎĵµ£¬ÄaÓ¦¸ÃÕaÑuд£º
$dom->load("file:///articles.xml");
£¨»oÕßÆaËuÀaÐ͵ÄÊý¾ÝÁ÷£(C)
Èç¹uÄaÏe½«XMLÎĵµÊa³oµ½a¯ÀÀÆ÷»o×oΪ±e×¼±e³o£¬Ê¹Óãº
print $dom->saveXML();
Èç¹uÄaÏe°ÑËu±£´ae³ÉÎļþ£¬ÇeʹÓãº
print $dom->save("newfile.xml");
£¨×¢ÒaÕaÑu×o»a½«Îļþ´oС¢Ë͵½stdout£(C)
µ±È»Õa¸oÀý×ÓûÓÐÌ«¶aµÄ¹¦ÄÜ£¬ÈÃÎÒÃÇÀ´×oÐ(C)¸uÓÐÓõġ£ÎÒÃÇÀ´È¡µÃËuÓеÄtitleÔªËØ¡£Óкܶa½¨¿ÉÒÔ°iµ½£¬×i¼oµ¥µÄ¾ÍÊÇʹÓÃgetElementsByTagName($tagname):
$titles = $dom->getElementsByTagName("title");
foreach($titles as $node) {
print $node->textContent . "\n";
}
textContentÊoÐÔ²¢²»ÊÇW3C±e×¼£¬Ëu¿ÉÒÔÈÃÎÒÃǺܽ±aµÄ¿iËÙ¶ÁÈ¡Ò»¸oÔªËصÄËuÓÐÎı¾½Úµa£¬Ê¹ÓÃW3CµÄ±e×¼¶ÁÈ¡ÊÇÏÂÃaeÕaÑu£º
$node->firstChild->data;
£¨ÕaʱºoÄaҪȱ£firstChild½aµaÊÇÄaÐeÒªµÄÎı¾½aµa£¬ñÔoÄa»¹µÃ±eÀuËuÓÐ×Ó½aµaÀ´²eÕÒ£(C)¡£
ÁiÍaÒ»¸oҪעÒaµÄÎÊÌaÊÇgetElementsByTagName()µ»ØÒ»¸oDomNodeList,¶ÔÏo£¬¶ø²»ÊÇÏñPHP4ÖÐget_elements_by_tagname()ÄÇÑuµ»ØÒ»¸oÊý×e£¬µ«ÊÇÕýÏñÄaÔÚÕa¸oÀý×ÓÖп´µ½µÄÄÇÑu£¬Äa¿ÉÒÔʹÓÃforeachÓi¾aÇaËɵıeÀuËu¡£ÄaÒ²¿ÉÒÔÖ±½ÓʹÓÃ$titles->item(0)À´ÃÎʽaµa¡£¸Ã½¨½«µ»ØµÚÒ»¸otitleÔªËØ¡£
ÁiÒ»¸oÈ¡µÃËuÓÐtitleÔªËصİi¨ÊÇ´Ó¸u½aµa±eÀu£¬Äa¿ÉÒÔ¿´µ½£¬Õa¸o½¨¸u¸´ÔÓ£¬µ«ÊÇÈç¹uÄaÐeÒªµÄ²»Ö»ÊÇtitleÔªËصÄʱºo£¬Õa¸o½¨Ò²¾Í¸uÁe»i¡£
foreach ($dom->documentElement->childNodes as $articles) {
//Èç¹u½ÚµaÊÇÒ»¸oÔªËØ(nodeType == 1)²¢ÇÒÃu×ÖÊÇitem¾Í¼ÌÐøÑ»
if ($articles->nodeType == 1 && $articles->nodeName == "item") {
foreach ($articles->childNodes as $item) {
//Èç¹u½ÚµaÊÇÒ»¸oÔªËØ£¬²¢ÇÒÃu×ÖÊÇtitle¾Í´oÓ¡Ëu.
if ($item->nodeType == 1 && $item->nodeName == "title") {
print $item->textContent . "\n";
}
}
}
}
XPath
XPaht ¾ÍÏñÊÇXMLµÄSQL£¬Ê¹ÓÃXPathÄa¿ÉÒÔÔÚÒ»¸oXMLÎĵµÖвeѯuºÏÒ»Ð(C)ģʽÓi¨µÄÌض¨½aµa¡£ÏeʹÓÃXPath»ñµÃËuÓÐtitle½aµa£¬Ö»ÐeÒªÕaô×o£º
$xp = new domxpath($dom);
$titles = $xp->query("/articles/item/title");
foreach ($titles as $node) {
print $node->textContent . "\n";
}
?>
ÕaÑuºÍʹÓÃgetElementsByTagName()½¨²i²»¶a£¬µ«ÊÇXpathҪǿ´oµÄ¶a£¬ÀýÈ磬Èç¹uÎÒÃÇÓÐÒ»¸otitleÔªËØÊÇarticleµÄ×ÓÔªËØ(¶ø²»ÊÇitemµÄ×ÓÔªËØ)£¬getElementsByTagName()¾Í»a½«Ëuµ»Ø¡£¶øʹÓÃ/articles/item/titleÓi¨£¬ÎÒÃÇÖ»»aµÃµ½ÔÚÖ¸¶¨Éi¶ÈºÍλÖõÄtitleÔªËØ¡£ÕaÖ»ÊÇÒ»¸o¼oµ¥µÄÀý×Ó£¬ÔÙÉiÈeÒ»µa¿ÉÄÜÊÇÕaÑu£º
/articles/item[position() = 1]/title µ»ØµÚÒ»¸oitemÔªËصÄËuÓÐ
/articles/item/title[@id = '23'] µ»ØËuÓк¬ÓÐidÊoÐÔ²¢ÇÒֵΪ23µÄtitle
/articles//title µ»ØËuÓÐarticlesÔªËØÏÂÃaeµÄtitle(ÒeÕß×¢£º//´u±iÈÎÒaÉi¶È)
ÄaÒ²¿ÉÒÔ²eѯº¬ÓÐÌØÊaÐÖµÜÔªËصĵa£¬º¬ÓÐÌØÊaÎı¾ÄÚÈݵÄÔªËØ£¬»oÕßʹÓÃÃuÃu¿Õ¼aµÈµÈ¡£Èç¹uÄa±ØÐe´oÁ¿µÄ²eѯXMLÎĵµ£¬Êʵ±µÄѧϰʹÓÃXPath»a½ÚÊ¡ÄaºÜ¶aʱ¼a£¬ËuʹÓüoµ¥£¬Ö´ÐÐËٶȿi£¬±È±e×¼µÄDOMÐeÒª¸uÉٵĴuÂe¡£
ÏoDOMÖÐдÈeÊý¾Ý
Îĵµ¶ÔÏoÄ£ÐͲ¢²»ÊÇÖ»ÄܶÁÈ¡ºÍ²eѯ£¬ÄaÒ²¿ÉÒÔ²Ù×÷ºÍдÈe¡£(DOM±e×¼ÓеaÈß³¤£¬ÒoΪ±aдÕßÏe¾¡Á¿Ö§³ÖÄܹ»ÏeÏñµ½µÄÿһ¸o»¾³£¬µ«ÊÇËu¹¤×÷µÄdz£ºÃ)¡£¿´¿´ÏÂÃaeÕa¸oÀý×Ó£¬ËuÔÚÎÒÃǵÄarticle.xmlÎļþÖÐÌi¼ÓÁËÒ»¸oÐÂÔªËØ¡£
$item = $dom->createElement("item");
$title = $dom->createElement("title");
$titletext = $dom->createTextNode("XML in PHP5");
$title->appendChild($titletext);
$item->appendChild($title);
$dom->documentElement->appendChild($item);
print $dom->saveXML();
Ê×ÏÈ£¬ÎÒÃÇ´´½¨ÁËËuÓÐÐeÒªµÄ½aµa£¬Ò»¸oitemÔªËØ£¬Ò»¸otitleÔªËغÍÒ»¸o°uº¬item±eÌaµÄÎı¾½aµa£¬È»ºoÎÒÃǽ«ËuÓеĽaµaÁ´½ÓÆðÀ´£¬°ÑÎı¾½aµa¼Óµ½titleÔªËØÉÏ,°ÑtitleÔªËؼӵ½itemÔªËØÉÏ£¬×iºoÎÒÃÇ°ÑitemÔªËزaÈeµ½articles¸uÔªËØÉÏ¡£ÏÖÔÚ£¬ÎÒÃǵÄXMLÎĵµÖÐÓÐÒ»¸oеÄÎÄÕÂÁбiÁË¡£
À(C)Õ¹Àa(class)
ºÃÁË£¬ÉÏÃaeµÄÀý×Ó¶¼¿ÉÒÔÔÚPHP4ÏÂÃaeÓÃDOMXMLÀ(C)Õ¹À´×o(Ö»ÊÇAPIÓÐÒ»Ð(C)²»Í¬)£¬Äܹ»×Ô¼ºÀ(C)Õ¹DOMÀaÊÇPHP5µÄÒ»¸oÐÂÌØÐÔ£¬ÕaʹµÃÊeд¸u¶a¿É¶ÁÐÔÇ¿µÄ´uÂe±aµÃ¿ÉÄÜ¡£ÏÂÃaeÊÇÓÃDOMDocumentÀaÖØÐÂдµÄÕu¸oÀý×Ó£º
class Articles extends DomDocument {
function construct() {
//±ØÐeµ÷ÓÃ!
parent::construct();
}
function addArticle($title) {
$item = $this->createElement("item");
$titlespace = $this->createElement("title");
$titletext = $this->createTextNode($title);
$titlespace->appendChild($titletext);
$item->appendChild($titlespace);
$this->documentElement->appendChild($item);
}
}
$dom = new Articles();
$dom->load("articles.xml");
$dom->addArticle("XML in PHP5");
print $dom->save("newfile.xml");
HTML
PHP5ÖÐÒ»¸o¾³£²»±»×¢Òaµ½µÄÌØÐÔÊÇlibxml2¿a¶ÔHTMLµÄÖ§³Ö£¬Äa²»½o¿ÉÒÔʹÓÃDOMÀ(C)Õ¹ÔØÈe½a¹¹Á¼ºÃ(well-formed)µÄXMLÎĵµ£¬»¹¿ÉÒÔÔØÈeǽa¹¹Á¼ºÃµÄ(not-well-formed)HTMLÎĵµ£¬°ÑËuµ±×o±e×¼µÄDOMDocument¶ÔÏo£¬Ê¹ÓÃËuÓÐÄÜÓõĽ¨ºÍÌØÐÔ£¬±ÈÈçXPathºÍSimpleXML¡£
µ±ÄaÐeÒªÃÎÊÒ»¸oÄaÎÞ¨¿ØÖÆÕ¾µaµÄÄÚÈÝʱ£¬HTMLµÄÐÔÄܾÍÏÔʾʮÖÓÐÓÃÁË¡£ÔÚ XPath, XSLT »o SimpleXMLµÄ°iÖuÏ£¬ÄaÊ¡µoÁËÐi¶a´uÂe£¬ÏñʹÓÃÕýÔo±i´iʽ±È½Ï×Öu´®»oÕßSAX½aÎoÆ÷¡£µ±HTMLÎĵµ½a¹¹²»ÊǺܺõÄʱºo£¬Õa¸o°i¨ÓÈÆaÓÐÓÃ(ÕaÊǸoƵ±µÄÎÊÌa£¡)¡£
ÏÂÃaeµÄ´uÂe»ñµÃ²¢½aÎophp.netµÄÊ×Ò³£¬½«µµÚÒ»¸otitleÔªËصÄÄÚÈÝ¡£
$dom = new DomDocument();
$dom->loadHTMLFile("http://www.php.net/");
$title = $dom->getElementsByTagName("title");
print $title->item(0)->textContent;
Çe×¢Òaµ±Ö¸¶¨ÔªËØûÓÐÕÒµ½Ê±£¬ÄaµÄÊa³o¿ÉÄÜ»a°uº¬´iÎo¡£Èç¹uÄaµÄÍøÕ¾»¹ÔÚʹÓÃPHPÊa³oHTML4´uÂe£¬ÓÐÒ»¸oºÃÏuÏ¢Òª¸aeËßÄa£¬DOMÀ(C)Õ¹²»½oÄÜÔØÈeHTMLÎĵµ£¬¶øÇÒ»¹Äܽ«ËuÃDZ£´aeΪHTML4¸ñʽµÄÎļþ¡£ÔÚÄaÌi¼ÓÍeDOMÎĵµºo£¬Ê¹ÓÃ$dom->saveHTML()À´±£´ae¡£Òª×¢ÒaµÄÊÇ£¬ÎªÁËʹÊa³oµÄHTML´uÂeuºÏW3C±e×¼£¬×iºÃ²»ÓÃʹÓà ÕuÆeµÄÀ(C)Õ¹?(tidy extension)¡£Libxml2 ¿aÖ§³ÖµÄHTML²¢²»»a¿¼Âǵ½Ã¿¸o¿ÉÄÜ¢ÉuµÄÊÂÇe£¬Ò²²»ÄܺܺõĴ¦ÀiÇͨÓøñʽµÄÊaÈe¡£
ÑeÖ¤
XMLÎĵµµÄÑeÖ¤Ô½À´Ô½ÖØÒªÁË¡£ÀýÈ磬Èç¹uÄa´ÓÒ»Ð(C)¹uÍa×ÊÔ´ÖлñµÃÁËÒ»¸oXMLÎĵµ£¬ÔÚÄa´¦Ài֮ǰÄaÐeÒª¼iÑeËuÊÇñuºÏij¸oȶ¨µÄ¸ñʽ¡£ÐÒÔ˵ÄÊÇÄa²»ÐeÒªÔÚPHPÖÐд×Ô¼ºµÄÑeÖ¤³ÌÐo£¬ÒoΪÄa¿ÉÒÔʹÓÃÈý¸oÓ¦ÓÃ×i¹aºµÄ±e×¼Ö®Ò»£¨DTD£¬XML Schema »oRelaxNG£(C)À´Íe³ÉËu¡£.
DTDÊÇÒ»¸o²uÉuÓÚSGMLʱ´uµÄ±e×¼£¬È±ÉÙÒ»Ð(C)XMLµÄÐÂÌØÐÔ£¨ÈçÃuÃu¿Õ¼a£(C),¶øÇÒÓÉÓÚËu²»ÊÇÓÃXMLдµÄ£¬ËuÒ²ºÜÄѱ»½aÎoºÍת»»¡£
XML SchemaiÊÇÓÉW3CÖƶ¨µÄÒ»¸o±e×¼£¬ËuÓ¦Óùaº£¬¼¸ºo°uº¬ÁËËuÓÐÑeÖ¤XMLÎĵµËuÐeÒªµÄÄÚÈÝ¡£
RelaxNG ÊǸ´ÔÓµÄXML Schema±e×¼µÄ¶ÔÍ£¬ÊÇÓÉ×ÔÓÉÕß×eÖ¯´´½¨µÄ£¬ÓÉÓÚËu±ÈXML Schema¸uÈÝÒ×ʵÏÖ£¬Ô½À´Ô½¶aµÄ³ÌÐo¿ªÊ¼Ö§³ÖRelaxNGÁË
Èç¹uÄaûÓÐÒÅÁoÏÂÀ´µÄ¼Æ»®Îĵµ»oÕßdz£¸´ÔÓµÄXMLÎĵµ£¬ÄÇôʹÓÃRelaxNG°É¡£ËuÊeдºÍÔĶÁ¶¼±È½Ï¼oµ¥£¬Ô½À´Ô½¶aµÄ¹¤¾ßÒ²Ö§³ÖËu¡£ÉoÖÁ»¹ÓÐÒ»¸o¹¤¾ß½ÐTrang£¬Ëu¿ÉÒÔ´ÓXML¶±¾ÖÐ×Ô¶¯´´½¨Ò»¸oRelaxNGÎĵµ¡£¶øÇÒÖ»ÓÐRelaxNG£¨ºÍÀÏ»¯µÄDTDS£(C)±»libxml2ÍeÈ«Ö§³Ö£¬¾¡¹Ülibxml2Ò²¼´½«ÍeÈ«Ö§³ÖML Schema¡£
ÑeÖ¤XMLÎĵµµÄÓi¨Ïaµ±¼oµ¥£º
$dom->validate('articles.dtd');
$dom->relaxNGValidate('articles.rng');
$dom->schemaValidate('articles.xsd');
Ä¿Ç°£¬ËuÓÐÕaÐ(C)¶¼Ö»»a¼oµ¥µÄµ»Øtrue»ofalse,´iÎo»a±»×oΪPHP¾¯¸aeÊa³o¡£ÏÔÈ»Ïeµ»Ø¸øÓû§ÓѺõÄÐÅÏ¢Õa²¢²»ÊÇÒ»¸oºÃÖ÷Òa£¬ÔÚPHP5.0ÒÔºoµÄ°ae±¾Ài»aÓÐËu¸ÄÉÆ¡£µ½µ×¸ÃÔoôʵÏÖÄ¿Ç°»¹ÔÚÌÖÂÛÖ®ÖУ¬µ«ÊÇ´iÎo±¨¸ae¿Ï¶¨»a´¦ÀiµÄ¸uºÃ¡£
SimpleXML
SimpleXML ÊÇPHPµÄXML¼Ò×aÖÐ×iºoÒ»¸o±»¼ÓÈeµÄ³ÉÔ±£¬¼ÓÈeSimpleXMLÀ(C)Õ¹µÄÄ¿µÄÊÇΪÁËÌa¹(C)Ò»¸oʹÓñe×¼¶ÔÏoÊoÐԺ͵u´uÆ÷ÃÎÊXMLÎĵµµÄ¸u¼oµ¥µÄ½¨¡£¸ÃÀ(C)չûÓÐÌ«¶aµÄ½¨£¬ËaÈ»Èç´ËËu»¹ÊÇÏaµ±Ç¿´oµÄ¡£´ÓÎÒÃǵÄÎĵµµÄÈ¡µÃËuÓÐtitle½Úµa±ÈÔÀ´ÐeÒª¸uÉٵĴuÂe¡£
$sxe = simplexml_load_file("articles.xml");
foreach($sxe->item as $item) {
print $item->title ."\n";
}
ÕaÊÇÔÚ¸Éʲô£¿Ê×ÏȽ«articles.xmlÔØÈeµ½Ò»¸oSimpleXML¶ÔÏo¡£È»ºoÈ¡µÃËuÓÐ$sxeÖеÄitemÔªËØ£¬×iºo$item->titleµ»ØtitleÔªËصÄÄÚÈÝ£¬¾ÍÊÇÕaÑu¡£ÄaÒ²¿ÉÒÔʹÓùØÁªÊý×e²eѯÊoÐÔ£¬Ê¹ÓÃ: $item->title['id']¡£
¿´µ½ÁË°É£¬ÕaºoÃaeÕaeÊÇÌ«ÉñÆaeÁË£¬ÓÐÐi¶a²»Í¬µÄ°i¨¿ÉÒԵõ½ÎÒÃÇÏeÒªµÄ½a¹u£¬ÀýÈç, $item->title[0]µ»ØºÍÀý×ÓÖÐÏaͬµÄ½a¹u£¬ÁiÒ»½Ãae£¬foreach($sxe->item->title as $item)Ö»µ»ØµÚÒ»¸otitle,²¢²»ÊÇËuÓÐÔÚÎĵµÖеÄtitleÔªËØ¡££¨¾ÍÏñÎÒÔÚXPathÖÐÔ¤ÆÚµÄÄÇÑu£(C)¡£
SimpleXML ʵ¼ÊÉÏÊÇʹÓÃÁËZendÒýÇae2ÐÂÌØÐԵĵÚÒ»¸oÀ(C)Õ¹¡£Òo´ËÒ²³ÉÁËÕaÐ(C)ÐÂÌØÐԵIJaÊÔµa£¬ÄaÒªÖªµÀÔÚ¿ª¢½×¶ÎbugsºÍ²»¿ÉÔ¤ÁϵĴiÎo¿É²»ÊÇÉÙÊý¡£
³ýÁËÉÏÃaeÀý×ÓÖÐËuʹÓõıeÀuËuÓнڵaµÄ½¨£¬ÔÚSimpleXMLÖÐÒ²ÓÐÒ»¸oXPath½Ó¿Ú£¬ËuΪÃÎʵ¥¸o½aµaÌa¹(C)Á˸u¼oµ¥µÄ°i¨¡£
foreach($sxe->xpath('/articles/item/title') as $item) {
print $item . "\n";
}
²»¿ÉñÈÏ£¬Õa¶Î´uÂeÒ²²»±ÈÇ°ÃaeÀý×ÓÖеĶ̣¬µ«ÊÇÌa¹(C)Á˸u¸´ÔÓ»o¸uÉiµÄǶÌ×XMLÎĵµ£¬Äa»a¢ÏÖºÍSimpleXMLÒ»ÆðʹÓÃXPath»a½ÚÊ¡ÄaºÜ¶aµÄÊaÈe¡£
Ïo SimpleXML ÎĵµÐ´ÈeÊý¾Ý
Äa²»½o¿ÉÒÔ½aÎoºÍ¶ÁÈ¡SimpleXML£¬¶øÇÒ»¹¿ÉÒԸıaSimpleXMLÎĵµ¡£ÖÁÉÙÎÒÃǼÓÈeÒ»Ð(C)À(C)Õ¹£º
$sxe->item->title = "XML in PHP5 "; //titleÔªËصÄÐÂÄÚÈÝ¡£
$sxe->item->title['id'] = 34; // titleÔªËصÄÐÂÊoÐÔ¡£
$xmlString = $sxe->asXML(); // ½«SimpleXML¶ÔÏo×oΪÐoÁл¯µÄXML×Öu´®µ»Ø
print $xmlString;
»¥ÓÃÐ×÷ÐÔ
ÓÉÓÚSimpleXMLÒ²ÊÇ»uÓÚlibxml2¿aµÄ£¬Äa¿ÉÒÔÔÚ¼¸ºo²»Ó°ÏiËٶȵÄÇe¿oÏÂÇaËɵĽ«SimpleXML¶ÔÏoת»¯³ÉDomDocument¶ÔÏo¡£(Îĵµ²»ÓýøÐÐÄÚ²¿¸´ÖÆ)£¬ÓÉÓÚÕa¸o»uÖÆ£¬ÄaÓµÓÐÁ˶þ¸o¶ÔÏoµÄ×iºÃ²¿Ö£¬Ê¹ÓÃÒ»¸oÊʺÏÄaÊÖ͹¤×÷µÄ¹¤¾ß°É£¬ËuÊÇÕaÑuʹÓõÄ:
$sxe = simplexml_import_dom($dom);
$dom = dom_import_simplexml($sxe);
XSLT
XSLTÊÇÓÃÀ´½«XMLÎĵµ×ª»»ÎªÆaËuXMLÎĵµµÄÓiÑÔ£¬XSLT±¾ÉiÊÇÓÃXML±aдµÄ£¬ÊoÓÚ¹¦ÄÜÐÔÓiÑÔ¼Ò×a£¬ÔÚ³ÌÐo´¦ÀiÉϺÍÃae¶Ô¶ÔÏoÓiÑÔ£¨ÏñPHP£(C)ÓÐËu²»Í¬¡£PHP4ÖÐÓжþÖÖXSLT´¦ÀiÆ÷£ºSablotron£¨ÔÚ¹aºÊ¹ÓõÄXSLTÀ(C)Õ¹ÖУ(C)ºÍLibxslt£¨ÔÚdomxmlÀ(C)Õ¹ÖУ(C)£¬ÕaÁ½ÖÖAPI²»»¥Ïa¼aeÈÝ£¬²¢ÇÒʹÓý¨Ò²²»Ïaͬ¡£PHP5Ö»Ö§³Ölibxslt´¦ÀiÆ÷£¬Ö®ËuÒÔÑ¡ÔñËuÊÇÒoΪËuÊÇ»uÓÚLibxml2µÄ£¬Òo´ËÒ²¸uuºÏPHP5µÄXML¸ÅÄi¡£
ÀiÂÛÉϽ«Sablotron°o¶¨µ½PHP5ÉÏÒ²ÊÇ¿ÉÄܵģ¬µ«ÊDz»ÐÒµÄÊÇûÈËÀ´×o¡£Òo´Ë£¬Èç¹uÄaÕýÔÚʹÓÃSablotron£¬Äa²»µÃ²»ÔÚPHP5ÖÐÇл»µ½libxslt´¦ÀiÆ÷¡£Libxslt ÊÇ´øÓÐJavascriptÒi³£´¦ÀiÖ§³ÖµÄSablotron£¬ÉoÖÁ¿ÉÒÔʹÓÃPHPÇ¿´oµÄÊý¾ÝÁ÷À´ÖØÐÂʵÏÖSablotron¶ÀÓеļƻ®´¦Ài£¨scheme handlers£(C)¡£´ËÍa£¬libxslt ÊÇ ×i¿iµÄXSLT´¦ÀiÆ÷Ö®Ò»£¬ËuÒÔÄa»¹Ãaѵõ½ÁËËٶȵÄÌaÉý¡££¨Ö´ÐÐËÙ¶ÈÊÇSablotronµÄ¶þ±¶£(C)¡£
ºÍ±¾ÎÄÌÖÂÛµÄÆaËuÀ(C)Õ¹Ò»Ñu£¬Äa¿ÉÒÔÔÚXSLÀ(C)Õ¹£¬DOMÀ(C)Õ¹ºÍvice versaÖ®¼a½»»»XMLÎĵµ£¬Êµ¼ÊÉÏ£¬Äa±ØÐeµÃÕaô×o£¬ÒoΪEXT/XSLÀ(C)Õ¹²¢Ã»ÓÐÔØÈeºÍ±£´aeXMLÎĵµµÄ½Ó¿Ú£¬Ö»ÄÜʹÓÃDOMÀ(C)Õ¹¡£Ò»¿ªÊ¼Ñ§Ï°XSLTת»»£¬Äa²»ÐeÒªÕÆÎÕÌ«¶aµÄÄÚÈÝ£¬ÕaÀiÒ²²»´aeÔÚW3C±e×¼£¬ÒoΪÕa¸oAPIÖдÓMozilla¡°½e¡±¹ýÀ´µÄ¡£
Ê×ÏÈÄaÐeÒªÒ»¸oXSLTÑuʽ±i£¬½«ÏÂÁÐÎı¾Õ³Ìuµ½Ò»¸oÐÂÎļþ²¢ÇÒ±£´ae»Òarticls.xsl
È»ºoÓÃPHP½Å±¾µ÷ÓÃËu£º:
/ ½«XMLºÍXSLÎĵµÔØÈeµ½DOMDocument¶ÔÏo/
$xsl = new DomDocument();
$xsl->load("articles.xsl");
$inputdom = new DomDocument();
$inputdom->load("articles.xml");
/ ´´½¨XSLT´¦ÀiÆ÷£¬²¢µ¼ÈeÑuʽ±i/
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
$proc->setParameter(null, "titles", "Titles");
/ ת»»²¢Êa³oXMLÎĵµ /
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
?>
ÉÏÃaeµÄÀý×ÓÊ×ÏÈʹÓÃDOMµÄ½¨load()ÔØÈeXSLTÑuʽ±iarticles.xsl£¬È»ºo´´½¨ÁËÒ»¸oеÄXsltProcessor¶ÔÏo£¬¸Ã¶ÔÏoµ¼µ½Á˺oÃaeҪʹÓÃÁËXSLTÑuʽ±i¶ÔÏo£¬²ÎÊý¿ÉÒÔÕaÑuÉeÖÃsetParameter(namespaceURI, name, value),×iºoXsltProcessor¶ÔÏoʹÓÃtransformToDoc($inputdom)¿ªÊ¼×ª»»²¢µ»ØÒ»¸oеÄDOMDocument¶ÔÏo¡£
. Õa¸oAPIµÄÓŵaÔÚÓÚÄa¿ÉÒÔʹÓÃͬһ¸oÑuʽ±iת»»Ði¶aXMLÎĵµ£¬Ö»ÐeÒª½«ËuÔØÈeÒ»´ÎÈ»ºoÖظ´Ê¹ÓÃËu£¬ÒoΪtransormToDoc()º¯Êý¿ÉÒÔÓ¦ÓÃÓÚ²»Í¬µÄXMLÎĵµ¡£
³ýÁËtransormToDoc()£¬»¹Óжþ¸oÓÃÓÚת»»µÄ½¨:transformToXML($dom)µ»ØÒ»¸o×Öu´®£¬transformToURI($dom, $uri)½«×ª»»Ö®ºoµÄÎĵµ±£´aeµ½Îļþ»oÒ»¸oPHPÊý¾ÝÁ÷¡£×¢ÒaÈç¹uÄaÏeʹÓÃXSLTµÄÒ»¸oÓi¨Èç »o indent="yes",Äa²»ÄÜʹÓÃtransformToDoc()£¬ÒoΪDOMDocument¶ÔÏo ²»Äܱ£´ae¸ÃÐÅÏ¢£¬Ö»Äܵ±Äa½«×ª»»ºoµÄ½a¹uÖ±½Ó±£´aeµ½×Öu´®»oÎļþÖÐʱ²ÅÄÜÕaÑu×o¡£
µ÷ÓÃPHPº¯Êý
XSLTÀ(C)Õ¹×iºoÒ»¸oмӵÄÌØÐÔÊÇÄܹ»ÔÚXSLT Ñuʽ±iÄÚ²¿µ÷ÓÃÈκÎPHPº¯Êý£¬Ö÷ÕÅÕýͳµÄXMLÖ§³ÖÕßÒ»¶¨²»»aϲ»¶Õa¸o¹¦ÄÜ(ÕaÑuµÄÑuʽ±iÓеa¸´ÔÓ£¬ºÜÈÝÒ×»iÏýÂß¼ºÍÉe¼Æ),ÔÚijÐ(C)µØ½È´ÊÇÊ®ÖÓÐÓõġ£µ±Éae¼°µ½º¯ÊýʱXSLT¾Í±aµÃºÜÓÐÏÞ£¬¼´Ê¹ÏeʵÏÖÓò»Í¬µÄÓiÑÔÊa³oÒ»¸oÈÕÆÚÒ²ÊÇdz£Âe³µÄ¡£µ«ÊÇʹÓÃÕa¸o¹¦ÄÜ£¬´¦ÀiÕaÐ(C)¾ÍºÍֻʹÓÃPHPÒ»ÑuÈÝÒס£ÏÂÃaeÊÇÏoXSLTÌi¼ÓÒ»¸oº¯ÊýµÄ´uÂe£º
function dateLang () {
return strftime("%A");
}
$xsl = new DomDocument();
$xsl->load("datetime.xsl");
$inputdom = new DomDocument();
$inputdom->load("today.xml");
$proc = new XsltProcessor();
$proc->registerPhpFunctions();
// ÔØÈeÎĵµ²¢Ê¹ÓÃ$xslÀ´´¦Ài
$xsl = $proc->importStylesheet($xsl);
/ ת»»²¢Êa³oXMLÎĵµ /
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
?>
ÏÂÃaeÊÇXSLTÑuʽ±idatetime.xsl£¬Ëu»aµ÷ÓÃÕa¸oº¯Êý¡£
ÏÂÃaeÊÇҪʹÓÃÑuʽ±iת»»µÄXMLÎĵµ£¬today.xml(ͬÀi£¬articles.xmlÒ²»aµÃµ½Í¬Ñu½a¹u)¡£
ÉÏÃaeµÄÑuʽ±i£¬PHP½Å±¾ºÍËuÓеÄXMLÎļþ»aÓõ±Ç°ÏµÍ³ÉeÖõÄÓiÑÔÊa³oÐÇÆÚµÄÃu×Ö¡£Äa¿ÉÒÔ¸øphp:function()Ìi¼Ó¸u¶aµÄ²ÎÊý£¬Ìi¼ÓµÄ²ÎÊý»a±»´«µÝ¸øPHPº¯Êý¡£ÕaÀiÓÐÒ»¸oº¯Êýphp:functionString(),Õa¸oº¯Êý×Ô¶¯½«ËuÓÐÊaÈeµÄ²ÎÊýת»»Îª×Öu´®£¬ËuÒÔÄa²»ÐeÒªÔÚPHPÀi½øÐÐת»»¡£
×¢ÒaÄaÐeÒªÔÚת»»Ö®Ç°µ÷ÓÃ$xslt->registerPhpFunctions()£¬ñÔoPHPº¯Êýµ÷Óý«ÒoΪ°²È«ÔÒo²»»a±»Ö´ÐУ¨ÄaʼÖÕÏaÐÅÄaµÄXSLTÑuʽ±iÂ𣿣(C)¡£Ä¿Ç°ÃÎÊϵͳ»¹Ã»ÓÐʵÏÖ£¬Ò²ÐiÔÚ½«À´PHP5µÄ°ae±¾ÖлaʵÏÖÕa¸o¹¦ÄÜ¡£
ÕªÒª
PHP¶ÔXMLµÄÖ§³ÖÒѾÏoÇ°Âo½øÁËÒ»´o²½£¬ËuuºÏ±e×¼£¬¹¦ÄÜÇ¿´o£¬»¥ÓÃÐ×÷ÐÔÇ¿£¬±»×÷ΪĬÈÏÑ¡Ïi°²×°£¬Òѱ»ÊÚȨʹÓá£Ð¼ÓÈeµÄSimpleXMLÀ(C)Õ¹Ìa¹(C)Á˼oµ¥¿iËÙÃÎÊXMLÎĵµµÄ½¨£¬¿ÉÒÔ½ÚÊ¡ÄaºÜ¶aµÄ´uÂe£¬ÓÈÆaÊǵ±ÄaÓнa¹¹»¯Îĵµ»oÕß¿ÉÒÔʹÓÃÇ¿´oµÄXPathʱ¡£
¸Ðлlibxml2¡ªPHP5 XMLÀ(C)Õ¹ËuʹÓõĵײa¿a£¬Ê¹ÓÃDTD£¬RelaxNG»oXML SchemaÑeÖ¤XMLÎĵµÏÖÔÚÒѾ±»Ö§³ÖÁË¡£
XSLÖ§³ÖÒ²µÃµ½ÁËУ¬ÏÖÔÚʹÓÃLibxslt¿a£¬±ÈÔÀ´µÄSablotron¿aÔÚÐÔÄÜÉÏÓкܴoÌa¸ß£¬¶øÇÒ£¬ÔÚXSLTÑuʽ±iÄÚ²¿µ÷ÓÃPHPº¯Êý¿ÉÒÔÈÃÄaд³o¸uÇ¿´oµÄXSLT´uÂe¡£
Èç¹uÄaÒѾÔÚPHP4»oÆaËuÓiÑÔÖÐʹÓÃÁËXML£¬Äa»aϲ»¶PHP5µÄXMLÌØÐԵģ¬XMLÔÚPHP5ÖÐÓÐÁ˺ܴoµÄ±a»¯£¬uºÏ±e×¼£¬ºÍÆaËu¹¤¾ß£¬ÓiÑÔÊÇͬµÈµÄ¡£
Á´½Ó
PHP 4 Ïa¹Ø
Domxml À(C)Õ¹: http://www.php.net/domxml/
Sablotron À(C)Õ¹: http://www.php.net/xslt/
Libxslt: http://www.php.net/manual/en/functi...-stylesheet.php
PHP 5 Ïa¹Ø
SimpleXML: http://www.php.net/simplexml/
Streams: http://www.php.net/manual/en/ref.stream.php
±e×¼
DOM: http://www.w3.org/DOM
XSLT: http://www.w3.org/TR/xslt
XPath: http://www.w3.org/TR/xpath
XML Schema: http://www.w3.org/XML/Schema
RelaxNG: http://relaxng.org/
Xinclude: http://www.w3.org/TR/xinclude/
¹¤¾ß
Libxml2, the underlying library: http://xmlsoft.org/
Trang, a Schema/RelaxNG/etc converter: http://www.thaiopensource.com/relaxng/trang.html
¹ØÓÚ×÷Õß
Christian StockerÊÇËÕÀeÊ¿Bitflux GmbH¹«Ë¾µÄ´´Ê¼È˺ÍCEO£¬ËuÊÇXSL£¬DOMºÍimagickÀ(C)Õ¹µÄά»¤ÈËÔ±£¬µÂÓiÊe¼®PHP de LuxeµÄºÏ×÷×÷Õߣ¬Í¬Ê±ÖÂÁ¦ÓÚÆaËu¿ªÔ´ÏiÄ¿£¬ÈçBitflux EditorºÍPopoon.¡£¿ÉÒÔͨÓÃchregu@php.net.ºÍËuÁªÏµ¡£