标签: simplexml-load-string

php simplexml_load_file - 无法在print_r中看到

我是simplexml parserPHP的新手.我已经运行了我找到的示例,它们的工作方式与广告一致.我不能让它与我的程序一起工作.我在这里搜索了几个小时.

我有一个名为core.xml的XML文件(注意节点标签有冒号):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <dc:title>Lecture 3</dc:title>
    <dc:creator>John Brown &amp; Greg Smith</dc:creator>
    <cp:lastModifiedBy>Greg Smith</cp:lastModifiedBy>
    <cp:revision>165</cp:revision>
    <dcterms:created xsi:type="dcterms:W3CDTF">2010-02-19T04:37:55Z</dcterms:created>
    <dcterms:modified xsi:type="dcterms:W3CDTF">2014-01-30T02:41:30Z</dcterms:modified>

</cp:coreProperties>
Run Code Online (Sandbox Code Playgroud)

我使用以下代码将其加载到解析器中:

if (file_exists('core.xml')){

    echo 'file exists <br>';
    $xml_core = simplexml_load_file('core.xml');

    print_r($xml_core);
} 
else 
{    
   exit('Failed to open core.xml.');  
}
Run Code Online (Sandbox Code Playgroud)

该文件存在,但我在print_r得到的是:

file exists    
SimpleXMLElement Object ( ) 
Run Code Online (Sandbox Code Playgroud)

我如何访问节点?我必须使用的其他XML文件有很多层.

谢谢

php xml simplexml xml-parsing simplexml-load-string

2
推荐指数
1
解决办法
1044
查看次数

simplexml_load_file和simplexml_load_string之间的区别

我想将xml文件放入程序中并将其放入数组中,以便将其放入表中。

我想知道如何做到这一点,并且已经阅读了php手册,但似乎无法掌握它。

要执行我想要的操作,我需要使用simplexml_load_string,还是需要同时命令这两个命令(simplexml_load_filesimplexml_load_string),因此将xml文件加载到程序中,然后将其转换为文件。还是simplesml_load_string为我做所有这些事情。

我也想知道get_object_vars将它放在数组周围会做什么。

php xml arrays simplexml simplexml-load-string

2
推荐指数
1
解决办法
1929
查看次数

PHP simplexml_load_file大小写返回false

我为我的PHP应用程序使用phpunit(100%覆盖率)进行单元测试,我有这个:

$xml = simplexml_load_string($soapResponse); 
if (false === $xml) {
    throw new \Exception('invalid XML'); 
}
Run Code Online (Sandbox Code Playgroud)

我找不到带有simplexml_load_stringreturn 的测试用例false

如果您有解决方案...谢谢

php phpunit simplexml simplexml-load-string

1
推荐指数
1
解决办法
4175
查看次数

simplexml_load_string失去了标签的顺序

我有以下XML:

<mobapp>    
    <form>
        <input type="text" name="target" id="target" value="" maxlength="8" required="true" pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"/>
        <label for="target"> Phone number</label> 
        <input type="number" name="amount" id="amount" min="0" maxlength="16" required="true"/> 
        <label for="amount"> Amount to load:</label> 
    </form> 
</mobapp>
Run Code Online (Sandbox Code Playgroud)

当我使用时,simplexml_load_string($theXML)我得到以下内容:

object(SimpleXMLElement)#150 (3) {
  ["input"]=>
  array(2) {
    [0] => object(SimpleXMLElement)#146 (1) {
      ["@attributes"]=> [... removed for brevity ...]
    }
    [1] => object(SimpleXMLElement)#146 (1) {
      ["@attributes"]=> [... removed for brevity ...]
    }
}
["label"]=>
  array(2) {
    [0] => [... removed for brevity ...]
    [1] => [... removed for brevity ...] …
Run Code Online (Sandbox Code Playgroud)

php xml simplexml simplexml-load-string

0
推荐指数
1
解决办法
124
查看次数