PDA

View Full Version : Ext-JS 4.1 - How to load static XML data into Ext.data.TreeStore



Bill M
22 Oct 2012, 8:31 PM
I was wondering if someone could point me in the direction of where I could find an example of a Ext.data.TreeStore being loaded from a static XML string (i.e. not from a file)? Or provide a short example?
I have seen plenty of examples where you can load it from a AJAX call to a server, but I have not been able to locate a single example where it is loaded with static XML JavaScript string that you could have embedded in your application file.
Would really appreciate the help.
Thanks.

scottmartin
24 Oct 2012, 7:02 AM
Is this static XML strng data that you will add yourself? Are you parsing data direct from page?

Scott.

Bill M
24 Oct 2012, 9:04 AM
Hi Scott,

Yes, this would be a XML string that I would add myself. Not parsed returned data from a Web Server somewhere.

I have tried the following:
var ingestedDataXML = '<Interfaces> \
<Interface> \

<id>1</id> \
<InterfaceName>IXXI</InterfaceName> \

</Interface> \
</Interfaces>

// Do I need to do this???
var ingestedDataXMLParsed = new DOMParser().parseFromString(ingestedDataXML, "text/xml");

var store_XMLTest = Ext.create('Ext.data.TreeStore', {

// root: ingestedDataXML <-- Do I want this???
// data: ingestedDataXML <-- Or this???
// data: ingestedDataXMLParsed <-- Or this???
autoLoad: true,
proxy: {

data: ingestedDataXMLParsed, // <-- Last thing I tried which I suspect is wrong
type: 'memory',

reader:{

type: 'xml',
root: 'Interfaces'

}

}
});

Note - I can successfully read in JSON formatted data using this TreeStore. Seems that the XML read requires a different configuration?

var jsonFmtString2 = {text: 'My Nav', items:[{text:'item1', leaf:true}, {text:'item2', leaf:true}]};

var store_Exper2 = Ext.create('Ext.data.TreeStore', {
root: jsonFmtString2,
autoLoad: true,
proxy: {

type: 'memory',
reader: {

type: 'json',
root: 'items'

}

}
});

Anyway, I then add the store to a Ext.Tree.Panel's 'store' configuration:
var somePanel = Ext.create('Ext.tree.Panel'), {
title: 'Some Panel Name',
store: store_XMLTest,

Appreciate your help with this!
...
...

scottmartin
24 Oct 2012, 9:15 AM
Before we venture off .. is there any reason you could simply not use an array store since this is just hard coded data?

Scott.

Bill M
24 Oct 2012, 9:59 AM
I am working with XML data. I am going to be performing XSLT's on internally generated XML data, that I would then display. I would like to display the resulting XML in some type of formatted fashion. From the examples I've seen online, it appears I should use the a TreeStore along with a TreePanel to accomplish this.

I thought that using the TreeStore with a XML Memory Proxy Reader was the way to read in XML data.

Bill M
24 Oct 2012, 11:22 AM
Hi Scott,

I made some progress wrestling with this thing. I now seem to have it loading up the 'parsed' XML String. It seems to show that there are 4 records present via the 4 folders displayed in the Tree, but it is not displaying any data for any of the records.

Here is where I am now:


Ext.define('InterfaceModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int', mapping: 'id' },
{ name: 'InterfaceName', type: 'string', mapping: 'InterfaceName' },
],
idProperty: 'id'
});


var ingestedDataXML = '\
<Interfaces> \
<Interface> \
<id>1<id> \
<InterfaceName>XXXLLXX</InterfaceName> \
<Interface> \
....
</Interfaces>';


var ingestedDataXMLParsed = new DOMParser().parseFromString(ingestedDataXML, "text/xml");

var store_XMLTest = Ext.create('Ext.data.TreeStore', {
model: 'InterfaceModel',
root: ingestedDataXMLParsed,
autoLoad: true,
proxy: {

type: 'memory',
reader:{

type: 'xml',
root: 'Interfaces',
record: 'Interface',
idProperty: 'id'

}

}

});

Do you have any ideas? Thanks.

Bill M
28 Oct 2012, 6:22 AM
Hi Scott,

Am I on my own with this problem? I don't see an answer from you, or anyone. Disappointed.

I need help with this issue.

Honestly, there should have be an example provided in your docs on how to do this. It should not be a big deal.

Dan

scottmartin
28 Oct 2012, 10:08 AM
If this is working in JSON and not XML as you stated, it could be that you have stumbled across a bug that needs to be addressed.

Please use the following template to create a bug report and we can have a look:
http://www.sencha.com/forum/showthread.php?138165

Please included a small working test case in your report. The more details, the better.

Scott.

Bill M
29 Oct 2012, 10:22 AM
Hi Scott,

I don't mean to be rude, but I gave you the full code already. I cannot believe that there is a bug with Ext-JS with a user base of over 1 million (if your advertisements are honest) that this toolkit cannot read static or inline XML.

Can this problem be transferred to another support person? From your postings it doesn't seem you are interested in helping me solve this problem.

Thanks.

scottmartin
29 Oct 2012, 12:07 PM
hmm...ok ...

Several things ...

This is an open community forum. Anyone can post and help you out. There is no transfer involved.

We have bug reports every day. You may have stumbled on something that has not been addressed, albeit you see it as common.

If you have purchased support, you are welcome to post your issue in the Premium Forums or the Support Portal. Have you purchased support? ... or do you have a licensed copy of ExtJS?

We place a priority on licensed support customers and also help out in the community forums as time permits. With hundreds a posts each day, some issue require a more detailed look that requires stepping through the SDK. You may have an issue requires this, or it may be a simple oversight.

I had a look at this on Sunday and was not able to get this load initially as well. So perhaps there is a problem in the SDK or simply with your code. I myself have always used a file, so I would have to research this in more detail.

As you mentioned, there are no immediate examples of your situation.

Have you narrowed this down to see if it loads from a file? Or is it just related to string only?

The reason I asked you to post this to the bugs forum, is that developers commonly review the bug reports and they may have a better understanding of what is going on.

You have a nice day.

Scott.