Created
June 10, 2012 05:53
-
-
Save toshimaru/2904049 to your computer and use it in GitHub Desktop.
dom4j test.
This file contains hidden or 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
import org.dom4j.Document; | |
import org.dom4j.DocumentException; | |
import org.dom4j.DocumentHelper; | |
public class Dom4jTest { | |
public static void main(String[] args) { | |
System.out.println("start"); | |
String xml = "<root><element name='toshi'>text1</element><element2>text2</element2></root>"; | |
try { | |
Document doc = DocumentHelper.parseText(xml); | |
// String s = doc.getRootElement().element("element").getText(); //Textとして取得 | |
// String s = doc.getRootElement().element("element").asXML(); //XMLとして取得 | |
// String s = doc.getRootElement().element("element").attributeValue("name");//nameのvalueを取得 | |
doc.getRootElement().element("element").setText("set text!");//Textをセット | |
System.out.println(doc.asXML()); | |
} catch (DocumentException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment