simplexml_load_string不返回名称中包含字母、连字符和数字的元素



我正在使用PHP 5.5.15,Codeigniter 3,并试图保存从Adobe Connect xml api检索到的数据。除了simplexml_load_string返回的对象中没有显示一个元素外,一切都很好。此元素名为x-998066622,来自Adobe Connect中的自定义用户字段。正在成功获取元素名称中带有连字符的其他值为了保护隐私,我更改了返回的xml和对象中的数据

public function getuserdata(){
    $query = $this->adobe_model->get_principals();
    echo "Be patient, this one takes a while...<br><br>";
    foreach($query->result() as $row){
        $url = 'https://uc-d.adobeconnect.com/api/xml?action=principal-info&principal-id='.$row->principal_id.'&session='.$this->session->userdata['breezesession'];
        $response = $this->get_response($url);
        $xml = simplexml_load_string($response);
        if(strtolower($xml->status['code']) == 'ok'){
            if(is_object($xml)){
                foreach($xml as $key => $value){
                    $data = array();
                    if($key == 'principal'){
                        echo "Updating for ".$value->name."<br><br>";
                        $data['first_name']     = (string)$value->{'first-name'};
                        $data['last_name']      = (string)$value->{'last-name'};
                        $data['company']        = (string)$value->{'x-company'};
                        $data['cost_center']    = (int)$value->{'cost-center'};
                        $data['dafis']          = (string)$value->{'x-998066622'};
                        $data['department']     = (string)$value->{'x-department'};
                        $data['phone']          = (string)$value->{'x-company-phone'};
                        $this->adobe_model->update_principal((int)$value['principal-id'],$data);
                    }
                }
            }else{
                // TO DO: put some error handling here
            } // if(is_object($xml) )
        }else{
            $this->login();
        } // if(strtolower($xml->status['code']) == 'ok')
    }
    echo "<strong>Done.</strong><br>";
    echo "<a href="".site_url()."">Back To main</a>";
}

XML

<?xml version="1.0" encoding="UTF-8"?>
<results>
    <status code="ok"/>
    <contact>
        <email>hgdfh@hdfgh.dhdfgh</email>
        <first-name>hdfhg</first-name>
        <last-name>dghfhfh</last-name>
    </contact>
    <preferences acl-id="852328317" lang="en" time-zone-id="4"/>
    <principal account-id="841422360" disabled="" has-children="false" is-hidden="false" is-primary="false" principal-id="852328317" tos-status="" type="user">
        <ext-login>sdfasd@afda.adf</ext-login>
        <login>afsdf@adf.adf</login>
        <name>qewrew ewrqwe</name>
        <email>asdfs@afa.affa</email>
        <first-name>xcbc</first-name>
        <last-name>xbvxcv</last-name>
        <x-company>zvcvxzcv</x-company>
        <x-company-phone>fgfsgsdfg</x-company-phone>
        <x-company-phone-key>sdfgdg</x-company-phone-key>
        <x-department>ssgffgdfg</x-department>
        <cost-center>sdfgf</cost-center>
        <x-998066622>sdfgsfgg</x-998066622>
    </principal>
</results>

数据转储

object(SimpleXMLElement)#3225 (13) {
    ["@attributes"]=> array(8) {
            ["account-id"]=> string(9) "sadfsdf"
            ["disabled"]=> string(0) ""
            ["has-children"]=> string(5) "false"
            ["is-hidden"]=> string(5) "false"
            ["is-primary"]=> string(5) "false"
            ["principal-id"]=> string(9) "sdfasdf"
            ["tos-status"]=> string(0) ""
            ["type"]=> string(4) "user"
        }
        ["ext-login"]=> string(19) "afdas@afsafds.adfds"
        ["login"]=> string(19) "fadf@dfghgd.hgjj"
        ["name"]=> string(12) "rerqwe qewrer"
        ["email"]=> string(19) "qer@qrqwer.ewrqwe"
        ["first-name"]=> string(6) "qerqwrqw"
        ["last-name"]=> string(5) "qrewrqw"
        ["x-company"]=> string(3) "qerqwer"
        ["x-company-phone"]=> string(14) "qwerqwerewq"
        ["x-company-phone-key"]=> string(10) "wqerwere"
        ["x-department"]=> string(20) "qwerqwerwer"
        ["cost-center"]=> string(9) "841779761"
        ["account-expiry-login-notif"]=> string(5) "false"
}

OK解决了这个问题。我整个下午都在做这个。谢谢菲尔的测试。

以下是正在发生的事情:如果该字段不包含任何值,Adobe Connect将不会在XML中返回该字段。并非所有配置文件都填写了此字段。原来我测试的那些没有填写。当我让它在所有用户中运行时,我在字段中为其中一些用户得到了一些结果。

拍打自己的前额

相关内容

最新更新