simplexml_load_string不返回名称中带字母,连字符和数字的元素

时间:2015-04-08 22:59:25

标签: php codeigniter simplexml adobe-connect

我正在使用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"
}

1 个答案:

答案 0 :(得分:1)

好的,弄清楚了。我整个下午都去过这个。谢谢,菲尔测试它。

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

在额头上砸自己