Loading
 
What's Next: View All Tutorial →

Extjs XML Parsing

Xml Parsing - Sample Example   Ext.onReady(function () { var xmlText = '<?xml version="1.0" encoding="UTF-8" ?><Students><Student><Name>aaa</Name><Surname>bbb</Surname>&l...

Published Date: 05/09/2014  Last Modified Date: 05/09/2014    New Post



Xml Parsing - Sample Example
 
Ext.onReady(function () {
    var xmlText = '<?xml version="1.0" encoding="UTF-8" ?><Students><Student><Name>aaa</Name><Surname>bbb</Surname></Student><Student><Name>ccc</Name><Surname>ddd</Surname></Student><Student><Name>aaa</Name><Surname>lala</Surname></Student></Students>',
        res,
        students = [],
        parser = new DOMParser(),
        xmlDoc = parser.parseFromString(xmlText, "application/xml"),
        tpl,
        list;
    res = Ext.DomQuery.select('Students/Student:contains(aaa)', xmlDoc);
    list = Ext.DomHelper.append(Ext.getBody(), {
        tag: 'ul',
        style: "border:1px red dashed; width: 100px;"
    });
    tpl = Ext.DomHelper.createTemplate({
        tag: 'li',
        id: 'item{0}',
        html: '{0} {1}'
    });
    Ext.each(res, function (item) {
        var name = Ext.DomQuery.selectValue('Name', item),
            sname = Ext.DomQuery.selectValue('Surname', item);
        tpl.append(list, [name, sname]);
    });
});

Ouput:
  • aaa bbb
  • aaa lala

 
Awaiting for Administrator approval





Tags: XML

← Back to list


Related Post




×