Mike521 Posted April 22, 2008 Share Posted April 22, 2008 I've probably been looking at this too long and need to just take a break. I have the following data in XML form, brought into an object via simplexml_load_string: object(SimpleXMLElement)#1 (1) { ["Dynamics_x0020_NAV_x0020_Data"]=> object(SimpleXMLElement)#2 (5) { ["Item_x0020_Stock_x0020_3406S"]=> object(SimpleXMLElement)#3 (2) { ["Item_x0020_Stock_x0020_3406S_Inventory"]=> string(5) "22964" ["Item_x0020_Stock_x0020_3406S_Qty_x0020_on_x0020_Sales_x0020_Order"]=> string(4) "1197" } } } When I try to get the data (aka the inventory) it comes up blank. But if I want the value of "Item_x0020_Stock_x0020_3406S" it returns data. For example the following code: $theInventoryObject = "Item_x0020_Stock_x0020_$style"; $theSalesOrderObject = "Item_x0020_Stock_x0020_$style"; $theInventoryName = "Item_x0020_Stock_x0020_$style_Inventory"; $theSalesOrderName = "Item_x0020_Stock_x0020_$style_Qty_x0020_on_x0020_Sales_x0020_Order"; $theItemInventory = $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theInventoryObject->$theInventoryName; $theItemSalesOrder = $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theSalesOrderObject->$theSalesOrderName; echo "<br>Item Inventory: $theItemInventory<br>Item Sales Order: $theItemSalesOrder<br>"; echo "<br>Inventory Object:<br>"; var_dump( $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theInventoryObject ); echo "<br>Sales Object:<br>"; var_dump( $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theInventoryObject->$theInventoryName ); outputs this: Inventory Object: object(SimpleXMLElement)#14 (2) { ["Item_x0020_Stock_x0020_3406S_Inventory"]=> string(5) "22964" ["Item_x0020_Stock_x0020_3406S_Qty_x0020_on_x0020_Sales_x0020_Order"]=> string(4) "1197" } Sales Object: object(SimpleXMLElement)#12 (0) { } Item Inventory: Item Sales Order: Can anyone see what I'm missing? Link to comment https://forums.phpfreaks.com/topic/102409-using-simplexml-cant-get-data/ Share on other sites More sharing options...
Barand Posted April 22, 2008 Share Posted April 22, 2008 What's the original XML and what are trying to output from it? Link to comment https://forums.phpfreaks.com/topic/102409-using-simplexml-cant-get-data/#findComment-524441 Share on other sites More sharing options...
Mike521 Posted April 23, 2008 Author Share Posted April 23, 2008 this is the original xml: <?xml version="1.0" encoding="utf-8"?> <Dynamics_x0020_NAV_x0020_Data> <Item_x0020_Stock_x0020_3406S> <Item_x0020_Stock_x0020_3406S_Inventory>22964</Item_x0020_Stock_x0020_3406S_Inventory> <Item_x0020_Stock_x0020_3406S_Qty_x0020_on_x0020_Sales_x0020_Order>1197</Item_x0020_Stock_x0020_3406S_Qty._x0020_on_x0020_Sales_x0020_Order> </Item_x0020_Stock_x0020_3406S> </Dynamics_x0020_NAV_x0020_Data> I'm trying to pull the values of 3406S_Inventory and 3406S_Qty I forgot to put in the first post: $style = 3406S; Link to comment https://forums.phpfreaks.com/topic/102409-using-simplexml-cant-get-data/#findComment-524856 Share on other sites More sharing options...
Mike521 Posted April 23, 2008 Author Share Posted April 23, 2008 I figured it out, the following lines were bugged: $theInventoryName = "Item_x0020_Stock_x0020_$style_Inventory"; $theSalesOrderName = "Item_x0020_Stock_x0020_$style_Qty_x0020_on_x0020_Sales_x0020_Order"; The variable was $style, but the way I tried to insert it into this string, PHP thought I was looking for a variable called $style_Inventory, similarly for the next line. I changed them to: $theInventoryName = "Item_x0020_Stock_x0020_" . $style . "_Inventory"; $theSalesOrderName = "Item_x0020_Stock_x0020_" . $style . "_Qty_x0020_on_x0020_Sales_x0020_Order"; and it worked perfectly Link to comment https://forums.phpfreaks.com/topic/102409-using-simplexml-cant-get-data/#findComment-524883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.