import java.util.Iterator;
import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class Test {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
String xml = "
single_trade_query utf-8 2088001513232645 20090422577264 ";
Document document = DocumentHelper.parseText(xml);
Element root = document.getRootElement();
List
elements = root.elements();
for (Iterator it = elements.iterator(); it.hasNext();) {
Element element = it.next();
List attributes = element.attributes();
for (int i = 0; i Attribute attribute = attributes.get(i);
if ("service".equals(attribute.getText())) {
System.out.println(element.getName() + " : "
+ element.getText());
}
}
}
}
}
import java.io.StringReader;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.InputSource;
public class Test {
public static void main(String args[]) {
String xml = "
single_trade_query utf-8 2088001513232645 20090422577264 ";
InputSource source = new InputSource(new StringReader(xml));
SAXReader reader = new SAXReader();
Document document = null;
try {
document = reader.read(source);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Element root = document.getRootElement();
System.out.println(document.elementByID("tt").getTextTrim());
System.out.println(root.elementByID("tt").getTextTrim());
}
}