Hi,
I wanted to delete a line from xml file which i did it. But after deletion of that line there is a blank space. Again if i am adding another line by using java that blank line remains as usual.
My xml file is :::::::
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<config>
<employee id = "1" name = "aa" />
<employee id = "2" name = "bb" />
<employee id = "3" name = "cc" />
</config>
For deletion of a line say employee having id = 2 i wrote the following java code:::::
[CODE=Java]
TransformerFact ory transformerFact ory = null;
Transformer transformer = null;
File file = new File("/src/java/config.xml");
int employeeNodeLen gth = 0;
int idValue = 0;
try {
Element employee_elem= null;
DocumentBuilder Factory documentBuilder Factory = DocumentBuilder Factory.newInst ance();
DocumentBuilder documentBuilder = documentBuilder Factory.newDocu mentBuilder();
Document document = documentBuilder .parse(new File("/src/java/config.xml"));
NodeList list = document.getEle mentsByTagName( "employee") ;
employeeNodeLen gth = list.getLength( );
for( int i = 0; i < employeeNodeLen gth ; i++) {
Node employeeNode= document.getEle mentsByTagName( "employee").ite m(i);
NamedNodeMap attributesList = employeeNode.ge tAttributes();
Node employeeId = attributesList. getNamedItem("i d");
idValue = Integer.parseIn t(employeeId.ge tTextContent()) ;
if(idValue == 2) {
System.out.prin tln("This "+employeeId.ge tTextContent()+ " node is going to be deleted");
employee_elem = (Element)docume nt.getElementsB yTagName("emplo yee").item(i);
// Remove the node
employee_elem.g etParentNode(). removeChild(emp loyee_elem);
// Normalize the DOM tree to combine all adjacent nodes
document.normal ize();
transformerFact ory = TransformerFact ory.newInstance ();
transformer = transformerFact ory.newTransfor mer();
transformer.set OutputProperty( OutputKeys.INDE NT,"no");
DOMSource source = new DOMSource(docum ent);
StreamResult result = new StreamResult(fi le);
transformer.tra nsform(source, result);
break;
}
}
} catch(Exception e) {
e.printStackTra ce();
}
[/CODE]
but after deletion of the line id = 2 there is a blank space between two lines employee id =1 and id = 3
I want that after removing one line/lines there should not be any blank space, it should be properly aligned
Thanks in advance
I wanted to delete a line from xml file which i did it. But after deletion of that line there is a blank space. Again if i am adding another line by using java that blank line remains as usual.
My xml file is :::::::
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<config>
<employee id = "1" name = "aa" />
<employee id = "2" name = "bb" />
<employee id = "3" name = "cc" />
</config>
For deletion of a line say employee having id = 2 i wrote the following java code:::::
[CODE=Java]
TransformerFact ory transformerFact ory = null;
Transformer transformer = null;
File file = new File("/src/java/config.xml");
int employeeNodeLen gth = 0;
int idValue = 0;
try {
Element employee_elem= null;
DocumentBuilder Factory documentBuilder Factory = DocumentBuilder Factory.newInst ance();
DocumentBuilder documentBuilder = documentBuilder Factory.newDocu mentBuilder();
Document document = documentBuilder .parse(new File("/src/java/config.xml"));
NodeList list = document.getEle mentsByTagName( "employee") ;
employeeNodeLen gth = list.getLength( );
for( int i = 0; i < employeeNodeLen gth ; i++) {
Node employeeNode= document.getEle mentsByTagName( "employee").ite m(i);
NamedNodeMap attributesList = employeeNode.ge tAttributes();
Node employeeId = attributesList. getNamedItem("i d");
idValue = Integer.parseIn t(employeeId.ge tTextContent()) ;
if(idValue == 2) {
System.out.prin tln("This "+employeeId.ge tTextContent()+ " node is going to be deleted");
employee_elem = (Element)docume nt.getElementsB yTagName("emplo yee").item(i);
// Remove the node
employee_elem.g etParentNode(). removeChild(emp loyee_elem);
// Normalize the DOM tree to combine all adjacent nodes
document.normal ize();
transformerFact ory = TransformerFact ory.newInstance ();
transformer = transformerFact ory.newTransfor mer();
transformer.set OutputProperty( OutputKeys.INDE NT,"no");
DOMSource source = new DOMSource(docum ent);
StreamResult result = new StreamResult(fi le);
transformer.tra nsform(source, result);
break;
}
}
} catch(Exception e) {
e.printStackTra ce();
}
[/CODE]
but after deletion of the line id = 2 there is a blank space between two lines employee id =1 and id = 3
I want that after removing one line/lines there should not be any blank space, it should be properly aligned
Thanks in advance
Comment