我在我的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