Code example for Element

Methods: getAttributes, getNodeName, getNodeType

0
			DocumentBuilder b = dbf.newDocumentBuilder();
 
			Document xmlDocument = b.parse(new InputSource(new StringReader(input)));
			Element rootElement = xmlDocument.getDocumentElement();  
 
			if(rootElement.getNodeType() == Node.ELEMENT_NODE) {
				String eName = rootElement.getNodeName();
				if(eName.equals("taskAssignment")) {
					NamedNodeMap nm = rootElement.getAttributes();
					if(nm != null) {
						Node nId = nm.getNamedItem("id");
						if(nId == null) {
							throw new InvalidParameterException("Error: id must be specified");
						} 
						String sId = nId.getNodeValue();
										 
						// Insert the data into the database 
						Class.forName("org.postgresql.Driver");	
						connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/de","ws", "ws1234");
						Statement statement = connection.createStatement();
						String sql1 = "UPDATE de_TaskAssignments SET status = \'";