我不知道他们怎么可能不同。差异在于客户端的空间比服务器的空间多,所以当我尝试在服务器上解析时得到这个: 解析 DOM - org.xml.sax.SAXParseException 这是代码,消息包含在评论:
Element rootElement = document.createElement(MyServer.NEW_PLAYER_CONNECTION_REQUEST);
Element participantTypeElement = document.createElement(MyServer.PARTICIPANT_TYPE);
Text textParticipantType = document.createTextNode(participantType);
participantTypeElement.appendChild(textParticipantType);
rootElement.appendChild(participantTypeElement);
document.appendChild(rootElement);
StringWriter sw = new StringWriter();
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(sw);
transformer.transform(source, result);
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}
catch (TransformerException t) {
t.printStackTrace();
}
try {
conn.setRequestMethod("POST");
} catch (ProtocolException e) {
e.printStackTrace();
}
conn.setRequestProperty("Content-Type", "text/xml");
//conn.setRequestProperty("Content-Length", "" + 8);
conn.setRequestProperty("Content-Language", "en-US");