View Full Version : Ext.data.BeanXmlReader

13 Feb 2008, 10:38 AM
This is a fairly simple XmlReader, but some of you might find it useful.

When I was creating a "Spring Java Bean " explorer, I came across a bug which prevents the word "class" being used when reading XML from a XHR response. This is annoying when the XML being read is java spring-like in nature, since often there are stanzas such as <bean class="com.x.y.z" /> and since it thinks they are className's and expects the Browser/DOM to properly convert the class attribute to valid css classes,, i could not find a way to get the "@class" to work, since it's hardcoded in the Ext.data.XmlReader..

So I created this Ext.data.BeanXmlReader (http://www.jsloader.com/twiki/pub/SpringThings/BeanCatalog/Ext.data.BeanXmlReader.js) which copies the "class" XML attribute to a provided attributename, so it can be made available by the superclass (XmlReader).

Here's the link to the page, (click the demo, etc to see it in use): http://www.jsloader.com/twiki/bin/view/SpringThings/

If you want the source, here it is:

Ext.data.BeanXmlReader = function(meta, recordType, newAttrName){
meta = meta || {};
Ext.data.BeanXmlReader.superclass.constructor.call(this, meta, recordType || meta.fields);
Ext.extend(Ext.data.BeanXmlReader, Ext.data.XmlReader, {

read : function(response){
return Ext.data.BeanXmlReader.superclass.read.call(this,response);

if(!doc) return;
var _beans=doc.getElementsByTagName("bean");
if(_beans || _beans.length){
for (var i=0;i<_beans.length;++i) {


beanReader=new Ext.data.BeanXmlReader({
id: '@xclass'
}, [{name:"extends",mapping:"@extends"},{name:"implements",mapping:"@implements"},{name:"xclass",mapping:"@xclass"}],
"xclass" /* the name of the attribute to copy @class to */