Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Advice: Reading XML

    I have an xml file. i want to read values and print it in label or flex table. Do we have anything to do that.

    My approach: i created a datasource to read xml and loaded it to listgrid. Now when iam trying to retrieve records from listgrid iam getting zero records even though it is printing 50 records on the screen. I am using grid.getRecords() to get records.

    Can anyone please help me in solving this in my approach or any new approach?

    Thanks

    #2
    Reread the javadocs for getRecords(), since your grid is databound it will return an empty list. Use getResultSet() or getRecordList() instead

    Comment


      #3
      i only have 1 record but iam getting length as 1000 for both getResultSet() or getRecordList().

      Comment


        #4
        Can you post your ds and relevant code.

        Comment


          #5
          XML:
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <DECISION><decision code="A">Approved</decision><decisionTimestamp>2010-04-06 14:10:03</decisionTimestamp><recommendedLoanAmount>0.0</recommendedLoanAmount><maxLoanAmount>0.0</maxLoanAmount><REASONS type="DECISION"><reason code="1X" source="EFUNDS_DDA">Bank inquiry within the last 30 days.</reason><reason code="0" source="APPLICATION">Internal System Decision</reason></REASONS><PROPERTIES><property name="clvScore">407</property><property name="scoresINQ">407</property></PROPERTIES></DECISION>
          My code:
          Code:
          MyDataSource dataSource = new MyDataSource(decisionXML);
          		dataSource.setDataFormat(DSDataFormat.XML);
          		System.out.println(decisionXML);
          		dataSource.setRecordXPath("//DECISION");
          		DataSourceField decisionCode = new DataSourceField("code", FieldType.TEXT,
          		"decision Code");
          		decisionCode.setValueXPath("decision/@code");
          		DataSourceField timeStamp = new DataSourceField("decisionTimeStamp", FieldType.TEXT,
          		"date time");
          		timeStamp.setValueXPath("decisionTimestamp");
          		dataSource.setFields(decisionCode, timeStamp);
          		ListGrid grid = new ListGrid();
          		grid.setAutoFetchData(true);
          		grid.setDataSource(dataSource);
          		grid.fetchData();
          		ResultSet listRecord = grid.getResultSet();
          		System.out.println("no of records1:"+ listRecord.getLength());
          		RecordList listRecord1 = grid.getRecordList();
          		System.out.println("no of records2:"+ listRecord1.getLength());
          i only have 1 record but its showing 1000 records. when i print on screen i got only 1 record

          Comment


            #6
            Ahh I see what your doing now, actually if you had:
            Code:
            public void onModuleLoad() {
              SC.showConsole();
            		
              VLayout l = new VLayout();
              final ListGrid grid = new ListGrid();
              grid.setAutoFetchData(true);
              grid.setDataSource(MyDataSource.getInstance());
              l.addMember(grid);
            
              IButton clickMe = new IButton("Click Me");
              clickMe.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                  SC.logWarn("Size: " + grid.getRecords().length);
                  SC.logWarn("Size: " + grid.getRecordList().getLength());
                  SC.logWarn("Size: " + grid.getResultSet().getLength());
                }
              });
              l.addMember(clickMe);
            		
              l.draw();
            }
            It would work because the records populate the grid on draw. However because you don't really care about the grid per se, rather just the xml data, might want to consider doing it server side and then sending to client, since your using a different widget like the FlexGrid.

            Comment

            Working...
            X