Results 1 to 6 of 6

Thread: XML Parsing: Multiple text elements with the same tag name

  1. #1

    Default XML Parsing: Multiple text elements with the same tag name

    Need to parse the following XML:

    HTML Code:
    <response>
        <messages>    
            <message type="error">Message 1</message>
            <message type="warning">Message 2</message>
            <message type="info">Message 3</message>    
        </messages>
    </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:

    Code:
                var stMain = new Ext.data.Store(
                {
                    url: "text.xml",
                    reader: new Ext.data.XmlReader(
                    {
                        record: "messages"
                    },
                    [
                        {name: 'message', mapping: 'message'},
                        {name: 'type', mapping: '[email protected]'}
                    ])
                });
    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.

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

  3. #3

    Default

    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"}]

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    That's not as easy with XmlReader as it is with JsonReader. Will need an override.

  5. #5

    Default

    Does Ext lean towards JSON rather than XML?

  6. #6
    Sencha User
    Join Date
    Sep 2011
    Location
    Bologna, Italy
    Posts
    12

    Default

    I think you have to use the "root" property of the XmlReader set to 'response'

Similar Threads

  1. XML Selection with Multiple Elements in a single record
    By stedav in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 27 May 2010, 1:11 AM
  2. Multiple XML elements in a record
    By roleary in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 18 Mar 2009, 11:22 AM
  3. How to Populate <p> tag from a XML file into a xml-grid?
    By lazyleo in forum Ext 2.x: Help & Discussion
    Replies: 9
    Last Post: 17 Feb 2009, 5:31 AM
  4. Not working mapping between text field and xml tag
    By Chamster in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 11 Jun 2008, 2:41 PM
  5. parsing XML
    By Akansha in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 6 Jun 2007, 6:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •