package Conexion;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;
import de.wurstgranulat.android.utils.xml.XmlUtil;
public class LogoutXML {
private Element root;
private Document doc;
LogoutXML (String client, String sessionKey) {
try {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
docBuilder = dbfac.newDocumentBuilder();
doc = docBuilder.newDocument();
root = doc.createElement("soapenv:Envelope");
root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
root.setAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/");
root.setAttribute("xmlns:wsdl","http://localhost/moodle/wspp/wsdl");
doc.appendChild(root);
Element header = doc.createElement("soapenv:Header");
root.appendChild(header);
Element login = doc.createElement("wsdl:logout");
login.setAttribute("soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/");
// Element body = doc.getElement
Element body = doc.createElement("soapenv:Body");
root.appendChild(body);
body.appendChild(login);
Element child = doc.createElement("client");
child.setAttribute("xsi:type", "xsd:string");
Node nodo = doc.createTextNode(client);
child.appendChild(nodo);
// child.setNodeValue(client); //el username
login.appendChild(child);
child = doc.createElement("sesskey");
child.setAttribute("xsi:type", "xsd:string");
// child.setNodeValue(sessionKey); //el password
nodo = doc.createTextNode(sessionKey);
child.appendChild(nodo);
login.appendChild(child);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String toString() {
try {
String myString = XmlUtil.xmlDocumentToString(doc);
return myString;
/* 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);
return sw.toString();
*/ } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
}
|