PDA

View Full Version : Help with XmlStore and XML collections



blahzay
5 Oct 2010, 1:45 PM
Hi all. I have an XmlStore defined as follows:

var store = new Ext.data.XmlStore({
url : "/remote_data/categories/all.xml",
fields : [{name : "child"}],
record : "element",
autoLoad : true,
listeners : {
load : function(obj, records){
Ext.each(records, function(record){
console.log(record);
});
}
}
});


How can I get the XmlStore to properly parse an xml document structured as follows:

<root>
<element>
<child>Child1</child>
<child><Child2</child>
<child>Child3</child>
</element>
<element>
<child>Child1</child>
<child><Child2</child>
</element>
</root>


Currently only the first child is being loaded into the XmlStore object.

tfcoding
5 Oct 2010, 1:52 PM
i guess your element has to much "child"s

blahzay
5 Oct 2010, 3:38 PM
i guess your element has to much "child"s


Thanks that was both hilarious and extremely helpful. Could a grown up or at least someone with something substantive to contribute please chime in.

Condor
6 Oct 2010, 1:18 AM
You can't. Your XML is invalid.

It needs to be:

<child>&lt;Child2</child>
or

<child><[!CDATA[<Child2]]></child>

blahzay
6 Oct 2010, 5:57 AM
You can't. Your XML is invalid.

It needs to be:

<child>&lt;Child2</child>
or

<child><[!CDATA[<Child2]]></child>


This was just a contrived example that I typed up in the forum WYSIWYG and not my real XML. The larger question isn't about why this particular XML isn't being parsed but rather how to deal with lists using EXTJS. From what I can gather EXT expects XML to match a certain format but I can't find any documentation on what that format is. I also gather that any XML outside if said expected format should be handled by extending the Ext XML parser. Is this correct?

Condor
6 Oct 2010, 6:28 AM
That depends on what you want as a result from the reader. If you only want a list of all children in all elements then you should have specified record:'child'.

If you want to read elements, but the 'child' fields should contain the list of children, then use an extra XmlReader in the 'child' field convert function to read the children.