I have an XML document that serves for a program in Java to save some values that will be read by another one in C #. It is not the best way to exchange values between languages (this is what has come out, but I accept suggestions for alternatives), but it works relatively well, the problem is that when I update XML values sometimes (apparently randomly) at the end of
[Fatal Error] test.xml:1:200: Content is not allowed in trailing section.
The error-free XML is as follows: (I've iden- tified the XML to facilitate *)
<?xml version="1.0" encoding="ASCII" standalone="no"?>
<Data>
<v1>0</v1>
<v2>0</v2>
<v3>0</v3>
<v4>60</v4>
<avg>60</avg>
<lvl1>70</lvl1>
<lvl2>85</lvl2>
<lvl3>100</lvl3>
<lvl4>115</lvl4>
<hRate>75</hRate>
</Data>
What looks like this:
<?xml version="1.0" encoding="ASCII" standalone="no"?>
<Data>
<v1>0</v1>
<v2>0</v2>
<v3>0</v3>
<v4>60</v4>
<avg>60</avg>
<lvl1>70</lvl1>
<lvl2>85</lvl2>
<lvl3>100</lvl3>
<lvl4>115</lvl4>
<hRate>75</hRate>
</Data>> //ERRO NESTA LINHA
The part of the code that updates the XML is this:
public static void UpdateValuesXML(XMLParametter... param)
{
try {
String tempDir = System.getProperty(property); //find windows temp folder
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(tempDir + fileName);
for (int i = 0; i < param.length; i++)
{
Node val = doc.getElementsByTagName(XMLValue(param[i].param)).item(0);
val.setTextContent(Integer.toString(param[i].value));
}
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(tempDir + fileName));
transformer.transform(source, result);
} catch (Exception ex) {}
}