gwt.xmlファイルに以下の記述を追加してください。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<inherits name="com.google.gwt.xml.XML"></inherits> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<message> | |
<from username="OCHI"></from> | |
<to username="OCHI1"></to> | |
<to username="OCHI2"></to> | |
<msg>よろしくー</msg> | |
<sbody><data>子供のデータ</data><data>子供のデータ2</data></sbody> | |
</message> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XML形式の文字列情報をXMLDocumentクラスに格納 | |
Document doc = XMLParser.parse(stringXML); | |
//ターゲットノードが一つの場合 | |
Node fromNode = doc.getElementsByTagName("from").item(0); | |
String sfrom = ((Element) fromNode).getAttribute("userName"); | |
Window.alert(sfrom); | |
//ターゲットノードが複数ある場合 | |
NodeList toNodeList = doc.getElementsByTagName("to"); | |
int num =toNodeList.getLength(); | |
Element ele; | |
for(int i=0;i<num;i++){ | |
//Attributeを取り出す場合はElementとして扱う | |
ele =(Element)toNodeList.item(i); | |
Window.alert(ele.getAttribute("userName")); | |
} | |
// Nodeの値を取り出す場合 | |
Node msgNode= doc.getElementsByTagName("msg").item(0); | |
String sMsg=msgNode.getFirstChild().getNodeValue(); | |
Window.alert("msg:"+sMsg); | |
//あるノードの子ノードの値を取ってくる場合 | |
Node bodyNode= doc.getElementsByTagName("sbody").item(0); | |
NodeList childs=bodyNode.getChildNodes(); | |
num =childs.getLength(); | |
Window.alert("数:"+num); | |
for(int i=0;i<num;i++){ | |
Node test= childs.item(i); | |
Window.alert("child:"+test.getFirstChild().getNodeValue()); | |
} |
0 件のコメント:
コメントを投稿