I am currently working on a website for a clothing store, and am having huge difficulties when it comes to formatting the output i am getting from an XML String.
The way it works (so far) is i make a call to the controller.php class provided by another developer (this has been tested and works superbly, i then format the XML using this code:
<script type= "text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "test1.xml",
dataType: "xml",
success: function(xml){
$(xml).find('ITEM').each(function(){
//stock confirmed
//Name confirmed
//confirmed item
var name = $(xml).find('NAME').text();
var description = $(xml).find('DESCRIPTION').text();
var id = $(xml).find('ID').text();
var price = $(xml).find('PRICE').text();
var imagepath = $(xml).find('IMAGE').text();
$(xml).find('SIZES').each(function(){
$(xml).find('SIZE').each(function(){
var symbol = $(xml).find('SYMBOL').text();
var quantity = $(xml).find('QTY').text();
});
});
$('<tr></tr>').html('<th>'+name+'</th><td>$'+description+'</td><td>$'+price+'</td>').appendTo('#chart');
});
}
});
});
</script>
and i get this output.
T-ShirtBench T-ShirtGrey T-ShirtSonic T-ShirtJeansBlack JeansBlue JeansJacketLeather JacketDenim JacketHatDenim HatJumperPlain JumperAdidas Jumper $A bench t-shirt thats black!Plain gre T-ShirtT-Shirt with Sonic DesignPair of black jeansPair of blue jeansBlack Leather JacketBlue Denim JacketBlue Denim Design Cowboy HatPlain Blue JumperStriped Adidas Jumper $12.994.9914.9934.9934.9984.9949.9919.9914.9924.99
My issue is that each of those is an individual item and it returns everything in blocks, here is a sample of my XML string.
<stock> <CATEGORY> <NAME>T-Shirt</NAME> <ITEM> <NAME>Bench T-Shirt</NAME> <DESCRIPTION>A bench t-shirt thats black!</DESCRIPTION> <ID>1</ID> <PRICE>12.99</PRICE> <IMAGE>benchtshirt.jpg</IMAGE> <SIZES> <SIZE> <SYMBOL>L</SYMBOL> <QTY>30</QTY> </SIZE> <SIZE> <SYMBOL>M</SYMBOL> <QTY>35</QTY> </SIZE> <SIZE> <SYMBOL>S</SYMBOL> <QTY>18</QTY> </SIZE> </SIZES> </ITEM> <ITEM> <NAME>Grey T-Shirt</NAME> <DESCRIPTION>Plain gre T-Shirt</DESCRIPTION> <ID>4</ID> <PRICE>4.99</PRICE> <IMAGE>grey-tshirt.jpg</IMAGE> <SIZES> <SIZE> <SYMBOL>L</SYMBOL> <QTY>1</QTY> </SIZE> <SIZE> <SYMBOL>M</SYMBOL> <QTY>23</QTY> </SIZE> <SIZE> <SYMBOL>S</SYMBOL> <QTY>1</QTY> </SIZE> </SIZES> </ITEM> </CATEGORY> </stock>
I know this question must get asked a million times a day, however i have googled for solutions. I have tried adding each item as i get it in the loop this caused it to over fill the box by about 300 copies of the data.
Any help, pointers, pseudocode, general encouragement would be sincerely appreciated.
Sincerely ~Daarkfall
p.s. test1.xml is a fuller version of the xml provided i am working on it locally and don't want to set up LAMP so for testing sake i am using that.

New Topic/Question
Reply



MultiQuote


|