Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7692221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:48:13+00:00 2026-05-31T20:48:13+00:00

I have an XML response that I’d like to bind and display to a

  • 0

I have an XML response that I’d like to bind and display to a GXT grid.

The basic example I’ve found online says to do the following:

    // defines the xml structure
    ModelType type = new ModelType();
    type.setRoot("records");
    type.setRecordName("record");
    type.addField("Sender", "Name");
    type.addField("Email");
    type.addField("Phone");
    type.addField("State");
    type.addField("Zip");

    // use a http proxy to get the data
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
        GWT.getHostPageBaseURL() + "data/data.xml");
    HttpProxy<String> proxy = new HttpProxy<String>(builder);

    // need a loader, proxy, and reader
    XmlLoadResultReader<ListLoadResult<ModelData>> reader = new XmlLoadResultReader<ListLoadResult<ModelData>>(
        type);

    final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(
        proxy, reader);

    ListStore<ModelData> store = new ListStore<ModelData>(loader);

This works just fine if your XML is in a simple structure (ie no nested elements).

However, my XML is more like this:

<myRoot>
  <myElement>
     <first>
       <time></time>
       <place></place>
     </first>
     <second>
       <time></time>
       <place></place>
     </second>
     <third>
       <time></time>
       <place></place>
     </third>
  </myElement>
  ...
</myRoot>

How can I represent this using ModelType in order for the Grid to properly display the results?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:48:14+00:00Added an answer on May 31, 2026 at 8:48 pm

    Abstract

    The key is how you parse the XML document to build the ModelData (extended here as ModelType).

    GXT showcase shows how to parse their example XML into beans, and you can use your favored XML parser to do the same.

    here is a snippet from their repositories, edited based on your XML data to demonstrate how it’s done:

    Code Example

    Service Implementation (with parser)

    public void parseXmlData() {
    
        try {
    
            // init parser / builder
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(getClass().getResourceAsStream("data.xml"));
            doc.getDocumentElement().normalize();
    
            // get first level
            NodeList myElementNodeList = doc.getElementsByTagName("myElement");
    
            // traverse first level
            for (int s = 0; s < myElementNodeList.getLength(); s++) {
    
                Node fstNode = myElementNodeList.item(s);
                if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
    
                    Element fstElmnt = (Element) fstNode;
                    NodeList myElementChildren = fstElmnt.getChildNodes();
    
                    // traverse second level
                    for (int c = 0; c < myElementChildren.getLength(); c++) {
    
                        Node cNode = myElementChildren.item(s);
                        if (cNode.getNodeType() == Node.ELEMENT_NODE) {
    
                            Element cElmnt = (Element) cNode;
                            NodeList timeList = cElmnt.getElementsByTagName("time");
                            NodeList placeList = cElmnt.getElementsByTagName("place");
    
                            // init beans
                            ModelType t = new ModelType();
                            // (scroll down to see how getValue() is implemented)
                            t.setTime(getValue(timeList, 0));
                            t.setPlace(getValue(placeList, 0));
    
                            // add to list
                            posts.add(t);
    
                        }
                    }
                }
            }
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private String getValue(NodeList fields, int index) {
        NodeList list = fields.item(index).getChildNodes();
        if (list.getLength() > 0) {
            return list.item(0).getNodeValue();
        } else {
            return "";
        }
    }
    

    you can, of course, extend this technique further (continue traversing deeper as you like) in order to match your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a response that comes from server side in xml format (partial like
I have a WebService that returns XML in a SOAP response: <?xml version=1.0 encoding=utf-8
I have XML that looks something like this: <Root xmlns=http://widgetspecA.com/ns> ...any... <WidgetBox> <A/> <B/>
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have an SOAP response that looks similar to this: <?xml version=1.0 encoding=UTF-8?> <soapenv:Envelope
I have a DataGrid that is populated by an xml response of a web
I have a site that give me this xml response on my GET request:
I have a response XML something like this - <Response> <aa> <Fromhere> <a1>Content</a1> <a2>Content</a2>
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.