Simplexml_load_string. Как добраться до элемента?

Загружаю я xml
$xml=simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?>
<Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:href="https://vcloud.volia.com/api/vApp/vm-d9cbdcfd-44ef-449c-b727-2c992226b8a2/virtualHardwareSection/cpu" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xsi:schemaLocation="http://www.vmware.com/schema/ovf http://www.vmware.com/schema/ovf http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://vcloud.volia.com/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
    <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
    <rasd:Description>Number of Virtual CPUs</rasd:Description>
    <rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
    <rasd:InstanceID>4</rasd:InstanceID>
    <rasd:Reservation>0</rasd:Reservation>
    <rasd:ResourceType>3</rasd:ResourceType>
    <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
    <rasd:Weight>0</rasd:Weight>
    <vmw:CoresPerSocket ovf:required="false">1</vmw:CoresPerSocket>
    <Link rel="edit" href="https://example.com/api/vApp/vm-d9cbdcfd-44ef-449c-b727-2c992226b8a2/virtualHardwareSection/cpu" type="application/vnd.vmware.vcloud.rasdItem+xml"/>
</Item>');


Потом вардамплю и вижу это:
SimpleXMLElement Object
(
    [Link] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [rel] => edit
                    [href] => https://example.com/api/vApp/vm-d9cbdcfd-44ef-449c-b727-2c992226b8a2/virtualHardwareSection/cpu
                    [type] => application/vnd.vmware.vcloud.rasdItem+xml
                )

        )

)


Как вывести значение атрибута rasd:Description ?
  • Вопрос задан
  • 157 просмотров
Решения вопроса 1
@bears
$xml = '<?xml version="1.0" encoding="UTF-8"?>
    <Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:href="https://vcloud.volia.com/api/vApp/vm-d9cbdcfd-44ef-449c-b727-2c992226b8a2/virtualHardwareSection/cpu" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xsi:schemaLocation="http://www.vmware.com/schema/ovf http://www.vmware.com/schema/ovf http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://vcloud.volia.com/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
        <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
        <rasd:Description>Number of Virtual CPUs</rasd:Description>
        <rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
        <rasd:InstanceID>4</rasd:InstanceID>
        <rasd:Reservation>0</rasd:Reservation>
        <rasd:ResourceType>3</rasd:ResourceType>
        <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
        <rasd:Weight>0</rasd:Weight>
        <vmw:CoresPerSocket ovf:required="false">1</vmw:CoresPerSocket>
        <Link rel="edit" href="https://example.com/api/vApp/vm-d9cbdcfd-44ef-449c-b727-2c992226b8a2/virtualHardwareSection/cpu" type="application/vnd.vmware.vcloud.rasdItem+xml"/>
    </Item>';

xml_parse_into_struct(xml_parser_create(), $xml, $values, $index);

var_dump($values[$index['RASD:DESCRIPTION'][0]]);
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы