Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

writeOpen - writeClose problem

Tom Clark
2014-04-15
2014-04-15
  • Tom Clark
    Tom Clark
    2014-04-15

    I'm having a problem getting the writeClose method to write the close tags. Here's my code:

        File testFile = new File("test.xml");
        System.out.println("Test file at " + testFile.getAbsolutePath());
        FileOutputStream fos = new FileOutputStream(testFile);
        XMLWriter testWriter = new XMLWriter(fos);
    
        Element dbElement = DocumentHelper.createElement("DATABASE");
        Element rowElement = DocumentHelper.createElement("ROW");
        rowElement.addAttribute("rowName","testRow");
        rowElement.addText("rowData");
    
        testWriter.startDocument();
        testWriter.writeOpen(dbElement);
        testWriter.write(rowElement);
        testWriter.writeClose(dbElement);
    

    My xml oputput looks like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <DATABASE><ROW rowName="testRow">rowData</ROW>

    Notice there is no </DATABASE> closing tag from the last statement (writeClose()). Anyone know what I'm doing wrong? Why is there no closing tag?
    In a previous test program, I was getting the closing tag at the top of the file instead of at the end.

     
  • Tom Clark
    Tom Clark
    2014-04-15

    I added a testWriter.flush(); at the end and it works OK now.