我在我的android应用程序中使用Java创建了一个XML文档。我必须在我的应用程序中调用Web服务,并将该XML作为参数传递给此应用程序。但我的问题是在XML中的每个标签之间创建了一个空白区域。如何删除XML中标签之间的空白
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element root = doc.createElement("subscriber");
doc.appendChild(root);
//creating child node for username
EditText txtusername=(EditText)findViewById(R.id.txtUserName);
subscriber[0]=String.valueOf(txtusername.getText());
Element UserName=doc.createElement("UserName");
UserName.setTextContent(subscriber[0]);
root.appendChild(UserName);
//creating child node for PASSWORD
EditText txtPassword=(EditText)findViewById(R.id.txtPassword);
subscriber[1]=String.valueOf(txtPassword.getText());
Element Password=doc.createElement("Password");
Password.setTextContent(subscriber[1]);
root.appendChild(Password);
//set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
//create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
String xmlString =sw.toString();
url = new URL("http://192.168.70.14/NewsLetter/subscribing.php?register= " + xmlString);
conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("Content-Type", "text/xml; charset=UTF-8");
dis = conn.getInputStream();
的XML是:
<subscriber> <UserName>miya</UserName> <Password>today</Password> </subscriber>
请给如何删除UserName
和Password
标签之间的空白空间的解决方案。
请出示XML – Mikpa 2010-11-25 07:17:39
它看起来像你喂养你的XML文档作为输入的XSLT转换。处理XSLT中仅限空白的文本节点有几种方法。请重新发布并发布您的样式表,以便我们为您提供帮助。 – 2010-11-25 16:24:07