I need to remove the processing instruction from a DOM. I load several files, merge them and save. But the problem is, that the result looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<frag>
Jó foxim és don Quijote húszwattos lámpánál ülve egy pár bűvös cipőt készít.
</frag>
<?xml version="1.0" encoding="iso-8859-2" standalone="no"?>
<frag>
Jó foxim és don Quijote húszwattos lámpánál ülve egy pár bűvös cipőt készít.
</frag>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<frag>
Jó foxim és don Quijote húszwattos lámpánál ülve egy pár bűvös cipőt készít.
</frag>
I haven’t found the way the <?xml ...?> process instruction can be either removed from DOM or ignored when saving the resulting DOM. I’m using Java 6 and the default parser.
There is no such method for removing the process instruction.
Your merge process is broken. I’ll bet you’re reading the fragment files and simply concatenating the strings together to create this example.
The right way to do it is to parse each fragment and add the Elements to want into the final DOM, which is then output.
Even if you remove the processing instruction, what you’ve posted is invalid XML. There’s no root tag that I can see, and you must have one and only one.