View Full Version : XML Parsing: Multiple text elements with the same tag name

12 Nov 2010, 6:58 AM
Need to parse the following XML:

<message type="error">Message 1</message>
<message type="warning">Message 2</message>
<message type="info">Message 3</message>
</response>I would like to end up with an error of objects:
message: "Message 1",
type: "error",
} etc..

The following code works to a point:

var stMain = new Ext.data.Store(
url: "text.xml",
reader: new Ext.data.XmlReader(
record: "messages"
{name: 'message', mapping: 'message'},
{name: 'type', mapping: 'message@type'}
});The problem is it will only return the first element ("Message 1").

How can I get the XMLReader to read all elements rather than just the first one?
I have thought about using convert but as far as the documenation goes I can't see how it will help.

Any help would be great.

12 Nov 2010, 7:37 AM

See Attribute Selectors

12 Nov 2010, 7:54 AM
But my problem is nothing to do with attributes.

I want the XML reader to return (for this example) an array of three objects (as describe) but the array only ever returns the first element i.e:
What I get:
[{message: "Message 1", type: "error"}]
What I want:
[{message: "Message 1", type: "error"}],[{message: "Message 2", type: "warning"}],[{message: "Message 3", type: "info"}]

12 Nov 2010, 8:16 AM
That's not as easy with XmlReader as it is with JsonReader. Will need an override.

12 Nov 2010, 8:17 AM
Does Ext lean towards JSON rather than XML?

15 Sep 2011, 5:17 AM
I think you have to use the "root" property of the XmlReader set to 'response'