Domanda

So che i browser supportano XML con l'approccio DOM

Ho un'applicazione che utilizza GWT e carica file sul server, al termine del caricamento, ho bisogno che il server risponda al client con un bean poiché si tratta di un caricamento di file, la risposta è gestita da un servlet.

Sono in grado di leggere una stringa sul client leggendo l'output prodotto dal servlet. Ho intenzione di convertire il mio bean in una struttura simile a XML che verrebbe riconvertita in un oggetto sul client.

Quindi, è possibile per il mio cliente trattare questa risposta come XML e iterare attraverso di essa?

È stato utile?

Soluzione

vedi di più su http://gwt.components.googlepages.com/simplexmlparser

private void parseMessage(String messageXml) {
  try {
    // parse the XML document into a DOM
    Document messageDom = XMLParser.parse(messageXml);

    // find the sender's display name in an attribute of the <from> tag
    Node fromNode = messageDom.getElementsByTagName("from").item(0);
    String from = ((Element)fromNode).getAttribute("displayName"); 
    fromLabel.setText(from);

    // get the subject using Node's getNodeValue() function
    String subject = messageDom.getElementsByTagName("subject").item(0).getFirstChild().getNodeValue();
    subjectLabel.setText(subject);

    // get the message body by explicitly casting to a Text node
    Text bodyNode = (Text)messageDom.getElementsByTagName("body").item(0).getFirstChild();
    String body = bodyNode.getData();
    bodyLabel.setText(body);    

  } catch (DOMException e) {
    Window.alert("Could not parse XML document.");
  }
}

Altri suggerimenti

puoi anche analizzare xml usando jquery, ed è facile racchiudere la chiamata jquery con jsni in GWT. molto meno dettagliato come dimostrato qui http://marcgrabanski.com/article/jquery- rende-analisi-xml-facile

modifica: GwtQuery potrebbe persino farlo? non sono sicuro, dal momento che non è una porta diritta.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top