How to import XML using PHP? -


i've been creating simple website client (i'm designer front-end skills) i've been thrown curve ball , want catalogue of products imported via csv or xml file. i've chosen xml option have less of clue csv.

would love guidance on how can start pulling out xml using php.

xml product example:

<?xml version="1.0" encoding="iso-8859-1"?> <style body="neck%2c+waist+and+cuff+ribs+in+cotton%2flycra%c2%ae%0atwin+needle+stitching+throughout%0ataped+back+neck%0a" brand="fruit+of+the+loom" code="ss8" date="20140303162801" footnote="garment+sizes+are+approximate+and+for+guidance+only%0a" material="80%25+cotton+belcoro%c2%ae+yarn%2f+20%25+polyester." name="fruit+of+the+loom+raglan+sweatshirt" type="adult" weight="280+gsm"> <sizes>     <row name="size:">         <col value="s"/>         <col value="m"/>         <col value="l"/>         <col value="xl"/>         <col value="xxl"/>     </row>     <row name="chest (to fit):">         <col value="35%2f37"/>         <col value="38%2f40"/>         <col value="41%2f43"/>         <col value="44%2f46"/>         <col value="47%2f49"/>     </row> </sizes> <skus>     <sku colour="blk">         <colours>             <colour hex="0f1315" name="black"/>         </colours>         <sizes>             <size cartonprice="490" cartonsize="36" name="s" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="36" name="m" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="36" name="l" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="36" name="xl" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="24" name="xxl" packprice="520" packsize="6" singleprice="560"/>         </sizes>     </sku>     <sku colour="bot">         <colours>             <colour hex="15451a" name="bottle"/>         </colours>         <sizes>             <size cartonprice="490" cartonsize="36" name="s" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="36" name="m" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="36" name="l" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="36" name="xl" packprice="520" packsize="6" singleprice="560"/>             <size cartonprice="490" cartonsize="24" name="xxl" packprice="520" packsize="6" singleprice="560"/>         </sizes>     </sku> 

....

please refer following code think you.

<!-- suppose book.xml file --> <?xml version="1.0"?> <catalog> <book id="bk101">   <author>gambardella, matthew</author>   <title>xml developer's guide</title>   <genre>computer</genre>   <price>44.95</price>   <publish_date>2000-10-01</publish_date>   <description>an in-depth @ creating applications   xml.</description>    </book>    <book id="bk102">   <author>ralls, kim</author>   <title>midnight rain</title>   <genre>fantasy</genre>   <price>5.95</price>   <publish_date>2000-12-16</publish_date>   <description>a former architect battles corporate zombies,   evil sorceress, , own childhood become queen   of world.</description>    </book> <catalog> 

and php:

<?php // loading xml file $xml = simplexml_load_file("books.xml"); echo "<h2>".$xml->getname()."</h2><br />"; foreach($xml->children() $book) {     echo "book : ".$book->attributes()->id."<br />";     echo "author : ".$book->author." <br />";     echo "title : ".$book->title." <br />";     echo "genre : ".$book->genre." <br />";     echo "price : ".$book->price." <br />";     echo "publish date : ".$book->publish_date." <br />";     echo "description : ".$book->description." <br />";     echo "<hr/>"; } ?> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -