PDA

View Full Version : XML Reader Problem



Geri
16 Feb 2011, 10:03 AM
Hi,
I am new at sencha and i have to decode this XML.
i can't find a solution to get the Product-id attribute, ProductMime urls and the other collections.


<ProductCollection>
<Product id="5">
<vendorProductId>123</vendorProductId>
<ean>0</ean>
<stock>no</stock>
<name>test</name><nameShort>
</nameShort>
<description>description</description>
<descriptionShort>descriptionShort</descriptionShort>
<deliveryScope></deliveryScope>
<price>89</price>
<priceTax>0</priceTax>
<priceGross>89</priceGross>
<productCurrency>0</productCurrency>
<ProductMimeCollection>
<ProductMime url="1.JPG" mimeType=""/>
<ProductMime url="1.JPG" mimeType=""/>
<ProductMime url="1.JPG" mimeType=""/>
<ProductMime url="1.JPG" mimeType=""/>
<ProductMime url="1" mimeType=""/>
</ProductMimeCollection>
<ProductReviewCollection rating="5" reviews="1">
<ProductReview id="1">
<active>1</active>
<customerId>2</customerId>
<dateCreated/>
<productId>5</productId>
<review>Reviewtext</review>
<shopId/>
<userEmail></userEmail>
<userName></userName>
<userRating>5</userRating>
</ProductReview>
</ProductReviewCollection>
<CrossSellingCollection>
<Product id="13"></Product>
</CrossSellingCollection>
</Product>

</ProductCollection>


can you show me how to fetch the attributes and elements,...
this was my way which did not work:

Ext.regModel('Products', {
fields: ['vendorProductId', 'ean', 'stock', {name: 'ProductMime', convert: (function(){
var reader2 = new Ext.data.XmlReader({
record: '> url',
fields: [
{name: 'url', mapping: '@url'}
]
});
return function(v, n) {
return reader2.readRecords(n).records;
};
});}
]
});

var store = new Ext.data.Store({
model: 'Products',
autoLoad:true,
proxy: {
type: 'ajax',
url : 'ajax/topten.xml',
reader: {
type : 'xml',
root : 'ProductCollection',
record: 'Product'
}
}



Please help me

Thanks for your Help!!

Animal
18 Feb 2011, 11:44 AM
You need to comprehend your code. Indenting in a javascript-specific way would help that.

You set the convert equal to a function. Not equal to the function which that function RETURNS



Ext.regModel('Products', {
fields: ['vendorProductId', 'ean', 'stock', {
name: 'ProductMime', convert: (function(){
var reader2 = new Ext.data.XmlReader({
record: '> url',
fields: [
{name: 'url', mapping: '@url'}
]
});
// Return a convert function which uses the Reader we declared above
return function(v, n) {
return reader2.readRecords(n).records;
};
})()
}]
});

var store = new Ext.data.Store({
model: 'Products',
autoLoad:true,
proxy: {
type: 'ajax',
url : 'ajax/topten.xml',
reader: {
type : 'xml',
root : 'ProductCollection',
record: 'Product'
}
}
});


In javascript, very precise indentation helps with this kind of problem