Results 1 to 5 of 5

Thread: How to read attribute values of XML tag using XmlReader

  1. #1
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    IL, USA
    Posts
    141

    Default How to read attribute values of XML tag using XmlReader

    I am trying to use XmlReader to read an XML file and store it in the data store. However, I cannot figure out how to read the parameter of a certain tag in XML file.

    My XML file is structured as follows:
    Code:
    <top_level>
        <second_level>
            <row num = "1">
                <name>ABC</name>
                .....
            </row_num>
            <row num = "2">
                <name>CBA</name>
                .....
            </row_num>
        </second_level>
    </top_level>
    And I am trying to use the following code to read values of "num" attribute and "name" tag out and store them into data store. However, I cannot figure out what I should put in the mapping part. Thanks for a lot. (BTW, where can I find a good document for Ext.DomQuery except http://www.jackslocum.com/blog/2007/...th-benchmarks/)

    Code:
    ds = new Ext.data.Store({
    			proxy: new Ext.data.HttpProxy({url: '/blabla.xml'}),
    			reader: new Ext.data.XmlReader({
    				record: 'row',
    				id: 'number'
    				},[
                                            // cannot figure out what should be put in the mapping
    					{name: 'number', type: 'int', mapping:'?????'},
    					{name: 'name'},
                                            ..........
    				]
    			)
    		});
    		ds.load();

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

    Default

    Have you read the documentation on XmlReader?

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

    Default

    id: '@num'

    It's an attribute, not a tag "<number>"

  4. #4
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    IL, USA
    Posts
    141

    Default

    Quote Originally Posted by Animal View Post
    Have you read the documentation on XmlReader?
    Thanks Animal. I finally figure out the magic with your help. I did read the document for XmlReader and DomQuery. And I would really appreciate if you can point out where I can find "@" is used for reading tag attribute. I just cannot find it.

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

    Default

    Look for the blog entry on jack's old website, jackslocum.com.

    Also, just play around with DomQuery on the Firebug console command line just to see what it can do. You can poke around to find what works quite easily with Firebug.

Posting Permissions

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