Hi

we need to import our products from an xml feed, I can read the xml into an multidimentional array from then on im stuck..

the xml feed is in the format shown below, what i need is to to loop the whole multidimentional array & output each into varaibles that i can use

ie .. $category_name = $arrXml[CREATED][CATEGORY][0]['@attributes']['name'];
but in a loop to display them all

-<STOREITEMS>
-<CREATED value="Fri Aug 26 1:01:01 BST 2011">
-<CATEGORY name=" > category name" id="69">
-<PRODUCT ITEM="1234">
<NAME>PRODUCT TITLE OR NAME</NAME>
<MODEL>MODEL NUMBER</MODEL>
<PRICE>7.00</PRICE>
<RRP>15.95</RRP>
<THUMB>BT2-Ss.jpg</THUMB>
<IMAGE>BT2-S.jpg</IMAGE>
<DESCRIPTION>product description</DESCRIPTION>
<POWER>product power<POWER/>
<SIZE>product dimentions<SIZE/>
-<ATTRIBUTES NAME="Size">
<ATTRIBUTEVALUES TITLE="Small" VALUE="16"/>
<ATTRIBUTEVALUES TITLE="Medium" VALUE="17"/>
<ATTRIBUTEVALUES TITLE="Large" VALUE="18"/>
</ATTRIBUTES>
</PRODUCT>
</CATEGORY>
</CREATED>
</STOREITEMS>
    neroag;10986822 wrote:

    we need to import our products from an xml feed

    The code you posted isn't (valid) XML.

    neroag;10986822 wrote:

    , I can read the xml into an multidimentional array from then on im stuck..

    If it was (valid) XML, you could use PHP DOM instead of doing things manually.

    neroag;10986822 wrote:

    what i need is to to loop the whole multidimentional array & output each into varaibles that i can use

    If you have it in an array, you allready have a variable you can use.

    neroag;10986822 wrote:

    ie .. $category_name = $arrXml[CREATED][CATEGORY][0]['@attributes']['name'];

    There is no need to assign an array element to a new variable. You will just have the same value in two places, and you are obviously allready accessing this value when you assign it to the new variable.

    neroag;10986822 wrote:

    but in a loop to display them all

    Control Structures, and more specifically, check the entries for "for" and "foreach".

    neroag;10986822 wrote:
    <STOREITEMS>
    	<CREATED value="Fri Aug 26 1:01:01 BST 2011">
    		<CATEGORY name=" > category name" id="69">
    			<PRODUCT ITEM="1234">
    				<NAME>PRODUCT TITLE OR NAME</NAME>
    				<MODEL>MODEL NUMBER</MODEL>
    				<PRICE>7.00</PRICE>
    				<RRP>15.95</RRP>
    				<THUMB>BT2-Ss.jpg</THUMB>
    				<IMAGE>BT2-S.jpg</IMAGE>
    				<DESCRIPTION>product description</DESCRIPTION>
    				<POWER>product power<POWER/>
    				<SIZE>product dimentions<SIZE/>
    				<ATTRIBUTES NAME="Size">
    					<ATTRIBUTEVALUES TITLE="Small" VALUE="16"/>
    					<ATTRIBUTEVALUES TITLE="Medium" VALUE="17"/>
    					<ATTRIBUTEVALUES TITLE="Large" VALUE="18"/>
    				</ATTRIBUTES>
    			</PRODUCT>
    		</CATEGORY>
    	</CREATED>
    </STOREITEMS>
    

    XML validation errors
    1. You are missing the xml opening tag.
    2. Some tags are preceeded by a hyphen (-)
    3.Some closing tags are malformed (</endtag> is correct, <endtag/> is not)

    <empty_element/> is correct, but that is not an endtag, it's an opening and closing tag for an empty element.

      thanks for the advice

      I have tried outputting the arrays using the following as an example ...

      echo $arrXml[CREATED][CATEGORY][0]['@attributes']['name'];

      but i cannot get the PRODUCT array details using this

      echo $arrXml[CREATED][CATEGORY][PRODUCT][0]['@attributes']['ITEM'];

      part of the arrays are ..

      Array ( [CREATED] => Array ( [@attributes] => Array ( [value] => Fri Aug 26 1:01:01 BST 2011 ) [CATEGORY] => Array ( [0] => Array ( [@attributes] => Array ( [id] => 69 [name] => > Games ) [PRODUCT] => Array ( [0] => Array ( [@attributes] => Array ( [ITEM] => 446 ) [NAME] => Nookii [MODEL] => 00nk01 [PRICE].... 

        Well, output your array data with preservation of whitespaces (just print_r using CLI or print_r with a pre-element in html and you should easily see what's wrong. Otherwise, indent the array information yourself.

          Write a Reply...