Can XML comments go anywhere?

前端 未结 4 1122
轮回少年
轮回少年 2021-01-07 23:52

I wrote a simple tool to generate a DBUnit XML dataset using queries that the user enters. I want to include each query entered in the XML as a comment, but the DBUnit API

4条回答
  •  一向
    一向 (楼主)
    2021-01-08 00:24

    Thanks for the answers everyone!

    As it turns out, the comment ahead of the file seemed to work, but when I delved into the DBUnit source, it is because validation is turned off.

    I did try a simple document load via:

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new File("/path/to/file"));
    

    and this fails with an exception because the XML Declaration is not the first thing (as others indicated would be the case).

    So, while DBUnit would work, I prefer to have valid XML, so I moved the comment to the end (since DBUnit generates the XML Declaration, it is not an option to place the comment below it, even though I would prefer that... at least not without modifying the XML after the fact, which would be more work than it is worth).

提交回复
热议问题