Output Notes document as XML document in Java

I heard that there is a function called NotesJSON **** that can exchange documents in the Notes database in JSON format, so I thought I'd try it ... Since it is a class that can be used from Notes10, I could not verify it in my Notes environment.

However, while searching for help etc., I found that a Notes document can be output in XML format by using a method called generateXML. It seems to be a useful function, but LotusScript cannot be used because it is a function provided only in Java.

Usability of generateXML class

When I actually used it, it was a ** amazing feature **. The generateXML class structurally exports all field information and values ​​in a document, but it also accurately exports multiple values ​​in list format and rich text field information.

When writing in LotusScript, after getting the document, get the fields in the document with For All item In doc.Items etc., and get various troublesome codes such as the code to get multiple values ​​for each field. I have to write it as "chima-chima", but if I write it in the generateXML class, it only takes one line ... There is only a little description in the help, but I think it is a feature that needs to be known more.

Source code

import lotus.domino.*;
import java.io.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {
    	  Session session = getSession();
    	  AgentContext agentContext = session.getAgentContext();

          // (Your code goes here)
          Database db = agentContext.getCurrentDatabase();
          View view = db.getView("Main");
          view.setAutoUpdate(false);
          Document tmpdoc;
          BufferedWriter bw = new BufferedWriter( new FileWriter("c:\\temp\\document.xml"));
          Document doc = view.getFirstDocument();
          while (doc != null) {
        	  System.out.println(doc.getItemValueString("Uname"));
        	  doc.generateXML(bw);
              tmpdoc = view.getNextDocument(doc);
              doc.recycle();
              doc = tmpdoc;
          }
          bw.close();
      } catch(Exception e) {
          e.printStackTrace();
       }
   }
}

Execution result

I created a test form with multiple types such as rich text and list, and confirmed that multiple documents are output in XML format.

Test forms and documents

I created multiple Notes documents with a test form with various types of fields such as text/rich text/time/checkbox. サンプル.png

Execution result

<document form='Main'>
<noteinfo noteid='912' unid='C7638A880050D1014925865B001F3A1B' sequence='1'>
<created><datetime>20210112T144104,91+09</datetime></created>
<modified><datetime>20210112T144104,92+09</datetime></modified>
<revised><datetime>20210112T144104,91+09</datetime></revised>
<lastaccessed><datetime>20210112T144104,92+09</datetime></lastaccessed>
<addedtofile><datetime>20210112T144104,92+09</datetime></addedtofile></noteinfo>
<updatedby><name>CN=Taro Yamada/O=Taro Yamada</name></updatedby>
<item name='Uname'><text>Ichiro Yamada</text></item>
<item name='UDate'><datetime>20210201</datetime></item>
<item name='UTimeS'><datetime>T091500,00</datetime></item>
<item name='UTimeE'><datetime>T180000,00</datetime></item>
<item name='Rtxt'><richtext>
<pardef id='1'/>
<par def='1'><run><font size='18pt' style='bold' name='Meiryo' pitch='variable'
 truetype='true' familyid='30' color='red'/>Rich text</run></par>
<par def='1'><run><font size='18pt' style='bold' name='Meiryo' pitch='variable'
 truetype='true' familyid='30' color='red'/></run></par></richtext></item>
<item name='CheckBox'><textlist><text>Saitama</text><text>Tokyo</text><text>Ibaraki</text></textlist></item>
<item name='Num'><number>12345678.9</number></item></document>

<document form='Main'>
<noteinfo noteid='90e' unid='4358C36AE3645EB44925865B001F2BF9' sequence='1'>
<created><datetime>20210112T144028,73+09</datetime></created>
<modified><datetime>20210112T144028,75+09</datetime></modified>
<revised><datetime>20210112T144028,74+09</datetime></revised>
<lastaccessed><datetime>20210112T144028,75+09</datetime></lastaccessed>
<addedtofile><datetime>20210112T144028,75+09</datetime></addedtofile></noteinfo>
<updatedby><name>CN=Taro Yamada/O=Taro Yamada</name></updatedby>
<item name='Uname'><text>Saburo Yamada</text></item>
<item name='UDate'><datetime>20210112T000000,00+09</datetime></item>
<item name='UTimeS'><datetime>T090000,00</datetime></item>
<item name='UTimeE'><datetime>T180000,00</datetime></item>
<item name='Rtxt'><richtext>
<pardef id='1' keepwithnext='true' keeptogether='true'/>
<par def='1'><run><font name='Meiryo' pitch='variable' truetype='true' familyid='30'/></run></par></richtext></item>
<item name='CheckBox'><text>Tokyo</text></item>
<item name='Num'><number>11</number></item></document>

<document form='Main'>
<noteinfo noteid='906' unid='A871F8B1625F2B0E4925865B001EFFCF' sequence='1'>
<created><datetime>20210112T143835,67+09</datetime></created>
<modified><datetime>20210112T143835,68+09</datetime></modified>
<revised><datetime>20210112T143835,67+09</datetime></revised>
<lastaccessed><datetime>20210112T143835,68+09</datetime></lastaccessed>
<addedtofile><datetime>20210112T143835,68+09</datetime></addedtofile></noteinfo>
<updatedby><name>CN=Taro Yamada/O=Taro Yamada</name></updatedby>
<item name='Uname'><text>Jiro Yamada</text></item>
<item name='UDate'><datetime>20210103T000000,00+09</datetime></item>
<item name='UTimeS'><datetime>T090000,00</datetime></item>
<item name='UTimeE'><datetime>T180000,00</datetime></item>
<item name='Rtxt'><richtext>
<pardef id='1' keepwithnext='true' keeptogether='true'/>
<par def='1'><run><font name='Meiryo' pitch='variable' truetype='true' familyid='30'/>Ah ah</run></par></richtext></item>
<item name='CheckBox'><text/></item>
<item name='Num'><text/></item></document>

Recommended Posts

Output Notes document as XML document in Java
Java formatted output [Notes]
Format XML in Java
[Java] Something is displayed as "-0.0" in the output
Implement XML signature in Java
Mixed Western calendar output in Java
Log output to file in Java
Notes on signal control in Java
java notes
Java marks PPT document as final state
Java creates a table in a Word document
Output Date in Java in ISO 8601 extended format
File output bean as JSON in spring
Partization in Java
Java Generics (Notes)
Changes in Java 11
[Java] Array notes
Rock-paper-scissors in Java
Display text as ASCII art in Java (jfiglet)
[Java] Study notes
I tried to output multiplication table in Java
Java serialization notes
Java 11 document summary
Pi in Java
Upload and download notes in java on S3
FizzBuzz in Java
Compare PDF output in Java for snapshot testing
How to input / output IBM mainframe files in Java?
Output true with if (a == 1 && a == 2 && a == 3) in Java (Invisible Identifier)
Work as a team! Face Null head-on in Java
Java11: Run Java code in a single file as is
Gzip-compress byte array in Java and output to file
Notes on how to use regular expressions in Java
About Java log output
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
[Java] Stream Collectors notes
NVL-ish guy in Java
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Java compressed PDF document
Comments in Java source
Azure functions in java
[Java] Control syntax notes
Java NIO 2 review notes
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java