SimpleXML php attributes missing

I have the following XML document here: Edit: (see below for a sample)

I use php / SimpleXML to hide it to an object to read it:

$xmlContent = file_get_contents($path . '/test.xml');
$tablesRaw = new SimpleXMLElement($xmlContent);
echo '<pre>';
print_r($tablesRaw);
echo '</pre>';

When I type r, I see the attributes for the field, but the attributes of an acceptable value are not displayed. Here is an example of raw xml (I need the value attribute):

<acceptable-value value="0">
    Unknown
</acceptable-value>

This is what I see when print_r:

[acceptable-values] => SimpleXMLElement Object
                                            (
                                                [acceptable-value] => Array
                                                    (
                                                        [0] => 
                    Unknown

                                                        [1] => 
                    Invalid

                                                        [2] => 
                    Deleted

                                                        [3] => 
                    Valid/Good

                                                        [4] => 
                    Inactive

                                                    )

                                            )

Any clues why attributes are not showing? Thanks in advance.

EDIT: request for some of the xml:

<field name="Address1Type" type="String"/>
<field name="Address2Street1" type="String"/>
<field name="Address2Street2" type="String"/>
<field name="Address2Type" type="String"/>
<field name="Address3Street1" type="String"/> 
<field name="Status" type="Integer" access="R">
            <acceptable-values>
                <acceptable-value value="0">
                    Unknown
                </acceptable-value>
                <acceptable-value value="1">
                    Invalid
                </acceptable-value>
                <acceptable-value value="2">
                    Deleted
                </acceptable-value>
                <acceptable-value value="3">
                    Valid/Good
                </acceptable-value>
                <acceptable-value value="4">
                    Inactive
                </acceptable-value>
            </acceptable-values>
        </field>
+5
source share
2 answers

print_r() SimpleXML. , PHP, , "" , , .

SimpleXML - , ($node['attribute']); , , - , -.

, SimpleXML, simplexml_dump(), ( ).

+7

SimpleXMLElement. :

$xmlContent = file_get_contents($path . '/test.xml');
$tablesRaw = new SimpleXMLElement($xmlContent);
$elements = $tablesRaw->table[22]->fields->field[31]->{'acceptable-values'}->children();

acceptable-value attributes():

foreach($elements as $element) {
    echo $element->attributes()->value . " ";
    echo trim($element[0]) . "\n";
}

XML, :

0 Unknown
1 Invalid
2 Deleted
3 Valid/Good
4 Inactive

, attributes() . ->value "".

0

All Articles