xml內容
<emails>
<email id=
<subject>hello world</subject>
<sender></sender>
<receivedDate>
</email>
<email id=
<subject>hello world demo
<sender></sender>
<receivedDate>
</email>
<email id=
<subject>hello world demo
<sender></sender>
<receivedDate>
</email>
</emails>
java解析實現
import org
import org
import org
import org
import javax
import javax
import javax
import java
import java
public class EmailsDemo {
public static void main(String[] args)
{
DocumentBuilderFactory factory = DocumentBuilderFactory
try {
DocumentBuilder builder = factory
InputStream is = EmailsDemo
Document document = builder
NodeList nodes = document
for (int i =
{
Node node = em(i);
Node id = node
System
}
} catch (ParserConfigurationException e) {
e
} catch (SAXException e) {
e
} catch (IOException e) {
e
}
}
}
groovy解析實現
def emails = new XmlParser()
emails
println
}
可以看到groovy解析代碼之少
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26896.html