Java Doc Transformer re-arranging xml

49 views Asked by At

In java I have read an xml file, add an attribue and value and write and xml back to a file.

The problem I am running into is that the doc transformer is re-arranging my xml.

Example:

Original

   <Valve lassName="AccessLogValveAdapter" directory="access_logs"  prefix="localhost." suffix=".log" pattern='%v %h %t "%r" %s %B %T "%{User-Agent}i"'/>

Modified

   <Valve className="AccessLogValveAdapter" directory="access_logs" pattern="%v %h %t "%r" %s %B %T "%{User-Agent}i"" prefix="localhost." suffix=".log"/>

Here is my code:

    boolean returnValue = false;
    String methodName = "docTransFormer() ";
    File file = new File(filePath);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = null;
    try
    {
        transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);

        StreamResult result = new StreamResult(file.getPath());
        transformer.transform(source, result);
        returnValue = true;
    }
    catch (TransformerConfigurationException e)
    {
        logger.info(EXCEPTIONCAUGHT + methodName + e.getMessage());
    }
    catch (TransformerException e)
    {
        logger.info(EXCEPTIONCAUGHT + methodName + e.getMessage());
    }
    return returnValue;
}

Any ideas how i can keep this in the original format?

0

There are 0 answers