rowEl.appendChild(dataEl); } //Add the row to the root element dataRoot.appendChild(rowEl); } } catch (Exception e) { Log.write(e.getMessage()); } finally { Log.write(" db_to_xml: Closing connections...");
}
//Add the root element to the document dataDoc.appendChild(dataRoot);
Node node1= mapRoot.getElementsByTagName("root").item(0); Element newRootInfo =(Element)node1; Log.write("After got newRootInfo ..."); //Retrieve the root and row information
NodeList oldRows = dataRoot.getElementsByTagName("row"); for (int i=0; i < oldRows.getLength(); i++){
//Retrieve each row in turn Element thisRow = (Element)oldRows.item(i);
//Create the new row Element newRow = newDoc.createElement(newRowName);
for (int j=0; j < newNodesMap.getLength(); j++) {
//For each node in the new mapping, retrieve the information //First the new information... Element thisElement = (Element)newNodesMap.item(j); String newElementName = thisElement.getAttribute("name");
//Then the old information Element oldElement = (Element)thisElement.getElementsByTagName("content").item(0); String oldField = oldElement.getFirstChild().getNodeValue();
//Get the original values based on the mapping information Element oldValueElement = (Element)thisRow.getElementsByTagName(oldField).item(0); String oldValue = oldValueElement.getFirstChild().getNodeValue();
Element newElement = newDoc.createElement(newElementName); newElement.appendChild(newDoc.createTextNode(oldValue));
NodeList newAttributes = thisElement.getElementsByTagName("attribute"); for (int k=0; k < newAttributes.getLength(); k++) { //Get the mapping information Element thisAttribute = (Element)newAttributes.item(k); String oldAttributeField = thisAttribute.getFirstChild().getNodeValue(); String newAttributeName = thisAttribute.getAttribute("name");
//Add the new element to the new row newRow.appendChild(newElement); } //Add the new row to the root newRootElement.appendChild(newRow); } //Add the new root to the document newDoc.appendChild(newRootElement);