Can anyone please help me how to remove the first tag from a XML file using java?
Remove:
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?">
from below XML file.
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?">
<Tag>
<subTag>tag1</subTag>
<subTag>tag2</subTag>
</Tag>
Below code:
public class Main
{
public static void main (String args[])
{
File file= new File("XMLfile.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db=factory.newDocumentBuilder();
Document doc=db.parse(file);
doc.getDocumentElement().normalize();
/*remove <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?"> */
}
}