trying flatten an complex XML string into a single table record



In convertig an XML string to an PHP object using simplexml_load_string(), I am faced with cases where a value may be an object or an array.



$myObject=simplexml_load_string($data);


In order to access this data It seems I will have to test existence of either object or array, then try to get object or iterate through array. Is their a more efficient way? Ultimately I am trying flatten an complex XML string into a single table record. (Note: this last statement is non-negotiable)


below is case where PackageReferenceNumber is sometimes an object value and sometimes an array value.



[0] => SimpleXMLElement Object
(
[PackageReferenceNumber] => Array
(
[0] => SimpleXMLElement Object
(
[Number] => 1
[Value] => IM25711111
)

[1] => SimpleXMLElement Object
(
[Number] => 2
[Value] => 4062742222
)

)



[24] => SimpleXMLElement Object
(
[PackageReferenceNumber] => SimpleXMLElement Object
(
[Number] => 1
[Value] => IM25728877
)

No comments:

Post a Comment