**
* 读取xml格式的参数
*/
StringBuffer readXml = new StringBuffer();
String line = null;
boolean is = false;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
readXml.append(line);
is = true;
}
} catch (Exception e) {
System.out.println(e.toString());
}
if (is) {
String xml = readXml.toString();
Document xmlDoc = null;
try {
xmlDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(
new ByteArrayInputStream(xml.getBytes()));
} catch (ParserConfigurationException e) {
System.out.println("ParserConfigurationException");
} catch (SAXException e) {
System.out.println("SAXException");
} catch (Exception e) {
System.out.println(e.toString());
}
System.out.println("......已读取xml格式的参数");
/**
* 参数1
*/
name = xmlDoc.getElementsByTagName("name").item(0).getFirstChild()
.getNodeValue();
password = xmlDoc.getElementsByTagName("password").item(0)
.getFirstChild().getNodeValue();
System.out.println("name>>>" + name + ",password>>>" + password);
}
* 读取xml格式的参数
*/
StringBuffer readXml = new StringBuffer();
String line = null;
boolean is = false;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
readXml.append(line);
is = true;
}
} catch (Exception e) {
System.out.println(e.toString());
}
if (is) {
String xml = readXml.toString();
Document xmlDoc = null;
try {
xmlDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(
new ByteArrayInputStream(xml.getBytes()));
} catch (ParserConfigurationException e) {
System.out.println("ParserConfigurationException");
} catch (SAXException e) {
System.out.println("SAXException");
} catch (Exception e) {
System.out.println(e.toString());
}
System.out.println("......已读取xml格式的参数");
/**
* 参数1
*/
name = xmlDoc.getElementsByTagName("name").item(0).getFirstChild()
.getNodeValue();
password = xmlDoc.getElementsByTagName("password").item(0)
.getFirstChild().getNodeValue();
System.out.println("name>>>" + name + ",password>>>" + password);
}
不用担心jdk1.3里面都有下面的类:
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;