gwt解析xml
来源:互联网 发布:怎样登录我的淘宝首页 编辑:程序博客网 时间:2024/06/06 15:52
import com.google.gwt.xml.client.Document;import com.google.gwt.xml.client.Node;import com.google.gwt.xml.client.NodeList;import com.google.gwt.xml.client.XMLParser;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."); }}