Results 1 to 3 of 3

Thread: problem in reading xml

  1. #1
    Sencha User
    Join Date
    Mar 2013
    Posts
    9
    Vote Rating
    0
      0  

    Default Unanswered: problem in reading xml

    Hello,everyone!
    I use store,model,proxy to read xml and meet a problem.
    my xml:
    <?xml version="1.0" encoding="utf-8"?>
    Code:
    <School>
        <Class>
            <Student>
                <StudentInfo>
                    <Code>1000001</Code>
                    <Name>qiang lai</Name>
                    <Sex>M</Sex>
                    <BirthDay>19860828</BirthDay>
                    <Age>27</Age>
                </StudentInfo>
                <Comment>comment:111</Comment>
                <StudentStatus>status:111</StudentStatus>
                <Parties>
                    <Party>
                        <PartyName>PartyName111-1</PartyName>
                        <PartyStatus>PartyStatus111-1</PartyStatus>
                        <CommentOne>CommentOne111-1</CommentOne>
                        <CommentTwo>CommentTwo111-1</CommentTwo>
                    </Party>
                    <Party>
                       <PartyName>PartyName111-2</PartyName>
                        <PartyStatus>PartyStatus111-2</PartyStatus>
                        <CommentOne>CommentOne111-2</CommentOne>
                        <CommentTwo>CommentTwo111-2</CommentTwo>
                    </Party>
                </Parties>
            </Student>
            <Student>
                <StudentInfo>
                    <Code>1000002</Code>
                    <Name>jj lai </Name>
                    <Sex>FM</Sex>
                    <BirthDay>19870828</BirthDay>
                    <Age>26</Age>
                </StudentInfo>
                <Comment>comment:222</Comment>
                <StudentStatus>status:222</StudentStatus>
                <Parties>
                    <Party>
                        <PartyName>PartyName222-1</PartyName>
                        <PartyStatus>PartyStatus222-1</PartyStatus>
                        <CommentOne>CommentOne222-1</CommentOne>
                        <CommentTwo>CommentTwo222-1</CommentTwo>
                    </Party>
                    <Party>
                       <PartyName>PartyName222-2</PartyName>
                        <PartyStatus>PartyStatus222-2</PartyStatus>
                        <CommentOne>CommentOne222-2</CommentOne>
                        <CommentTwo>CommentTwo222-2</CommentTwo>
                    </Party>
                    <Party>
                       <PartyName>PartyName333-2</PartyName>
                        <PartyStatus>PartyStatus333-2</PartyStatus>
                        <CommentOne>CommentOne333-2</CommentOne>
                        <CommentTwo>CommentTwo333-2</CommentTwo>
                    </Party>
                </Parties>
            </Student>
        </Class>
    </School>
    and the js code reading xml:
    Code:
     
    readXml:function(){
     Ext.define('School',{
          extend:'Ext.data.Model',
          config:{
        proxy: {
         type: 'ajax',
         url : 'xmldatafolder/StudentContent.xml',
         reader: {
          type  : 'xml',
          record: 'School'
         }
        },
           hasMany:{
            model:'Student',
            name :'getStudents',
            associationKey: 'Student'
           },
          }
      });
      
     Ext.define('Student',{
          extend:'Ext.data.Model',
          config:{
           fields: ['Comment', 'StudentStatus','Code', 'Name', 'Sex', 'BirthDay','Age'],
           belongsTo:['School'],
           hasMany:{
            model:'Party',
            name :'getPartys',
            associationKey: 'Parties'
           },
              proxy: {
               type:'ajax',
               url : 'xmldatafolder/StudentContent.xml',
               reader: {
                type: 'xml',
                root: 'Class',
                record: 'StudentInfo'
               }
              }
          }
      });
     Ext.define('Party',{
          extend:'Ext.data.Model',
          config:{
              fields:['PartyName', 'PartyStatus', 'CommentOne', 'CommentTwo'],
              belongsTo:['Student'],
              proxy: {
               type:'ajax',
               url : 'xmldatafolder/StudentContent.xml',
               reader: {
                type: 'xml',
                root: 'Parties',
                record: 'Section'
               }
              }
          }
      });
     OutPatients.load(1, {
       success: function(outpatient) {
        var res = outpatient.getStudents();
        res.load({
         callback:function(records, operation, success){
          for(var i = 0; i < records.length; i++){
           var result = records[i];
           console.log("Comment: " + result.get('Comment'));
           console.log("StudentStatus: " + result.get('StudentStatus'));
           console.log("Code: " + result.get('Code'));
           console.log("Name: " + result.get('Name'));
           console.log("Sex: " + result.get('Sex'));
           console.log("BirthDay: " + result.get('BirthDay'));
           console.log("Age: " + result.get('Age'));
           console.log("--------------------------------------");
           var sec = result.getPartys();
           sec.load({
            callback:function(cos, operation, success){
              for(var j = 0; j < cos.length; j++){
               var ret = cos[j];
               console.log("PartyName: " + ret.get('PartyName'));
               console.log("PartyStatus: " + ret.get('PartyStatus'));
               console.log("CommentOne: " + ret.get('CommentOne'));
               console.log("CommentTwo: " + ret.get('CommentTwo'));
               console.log("--------------------------------------");
              }
            }
           });
          }
         }
        });
       }
      });
    },
    The problems is:When I use the config"root: 'Parties'," in the model "'Party'", for each studnet I will only get parties infomation in the first xml tags "parties",info in other "parties' tags never appear,
    and When I delete the config"root: 'Parties'," in the model "'Party'", for each studenti get all infomation in all "parties" tags,but not info of the current student.
    How to get the information only of the current student.
    can you help me?
    thanks in advance.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,336
    Answers
    3885
    Vote Rating
    1296
      0  

    Default

    What is OutPatients?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2013
    Posts
    9
    Vote Rating
    0
      0  

    Default

    "OutPatients" should be "School" .

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
  •