duanbi8089 2013-12-12 18:24 采纳率: 100%
浏览 46

如何使用PHP的DOM,XML / XSLT扩展

I have the following PHP code where I am trying to transform an XML file.

Below is the PHP code:

$xmldoc = new DOMDocument();
$xmldoc->load('somefile.xml');


$xsldoc = new DOMDocument();
$xsldoc->load('somexsltfile.xslt');

$xslt = new XSLTProcessor();
$xslt->importStylesheet($xsldoc);


$result = $xslt->transformToDoc($xmldoc);  
$result->save('somefile.xml');

While running this php file I am unable to load the xml file. Looks like I need to install libxml, libxslt library since I am using XSLTProcessor and DOMDocument. My build server is using PHP 5.3.10 version. In the php.ini file I see only following extensions loaded (built-in?) :

[PHP_GD2]
extension=php_gd2.dll
[PHP_OCI8]
extension=php_oci8.dll
[PHP_OCI8_11G]
extension=php_oci8_11g.dll

But when I run “php –m” on CLI I get:

[PHP Modules]
bcmath
calendar
com_dotnet
Core
ctype
date
dom
ereg
filter
ftp
gd
hash
iconv
json
libxml
mcrypt
mhash
mysqlnd
oci8
odbc
pcre
PDO
Phar
Reflection
session
SimpleXML
SPL
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

So now does that mean these above listed extensions are available to me on my build server? If yes then how can I access them in my php code? And if not how can I get them installed on my build machine?Which are the dll’s required for these functions used in my php code like DOMDocument and XSLTProcessor() functions?

Please suggest.

Thanks in advance!

Updated: I installed the XSL extension and I now see extension=php_xsl.dll in my php.ini file

But what do i do for DOMDocument?

Also when I run phpinfo() I see

DOM/XML => enabled, libXML support => active, XML Support => active, 
XSL => enabled
libxslt Version => 1.1.23

So now how will I make use of these extensions which are enabled? Thanks

  • 写回答

1条回答 默认 最新

  • doumei8126 2013-12-19 11:41
    关注

    I have tested the following code,

    $xmlDoc = new DOMDocument();
    $xmlDoc->load("note.xml");
    $x = $xmlDoc->documentElement;
    foreach ($x->childNodes AS $item)
    {
      print $item->nodeName . " = " . $item->nodeValue . "<br>";
    }
    

    And the note.xml is as follows,

    <?xml version="1.0" encoding="UTF-8"?>
     <note>
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
     </note>
    

    Please let me know if you face any troubles.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog