In-Line XML Editor: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Overview=
=Overview=


<tt>InLineXMLEditor</tt> is an API that applies in-line configuration modifications in XML files.
<tt>InLineXmlEditor</tt> is an API that can be used to modify XML files on disk directly from Java programs.


A typical usage pattern is the following:
A typical usage pattern is the following:
Line 11: Line 11:
<pre>
<pre>
File file = ...;
File file = ...;
InLineXMLEditor editor = new InLineXMLEditor(file);
InLineXmlEditor editor = new InLineXmlEditor(file);


boolean changeOccurred = editor.set("/path/in/document", "value");
boolean changeOccurred = editor.set("/path/in/document", "value");
Line 17: Line 17:
if (changeOccurred) {
if (changeOccurred) {


     editor.write();
     editor.save();
}
}
else {
else {
Line 29: Line 29:


The modification preserves the original format, nothing is modified except the value that is being changed.
The modification preserves the original format, nothing is modified except the value that is being changed.
The editor can be also used to read values:
<pre>
File file = ...;
InLineXmlEditor editor = new InLineXmlEditor(file);
String value = editor.get("/path/in/document");
</pre>
=Thread Safety=
As per novaordis-utilities 4.2.1, the implementation is NOT thread safe,  the editor must be accessed and used from a single thread at a time.

Latest revision as of 07:51, 12 November 2016

Internal

Overview

InLineXmlEditor is an API that can be used to modify XML files on disk directly from Java programs.

A typical usage pattern is the following:

File file = ...;
InLineXmlEditor editor = new InLineXmlEditor(file);

boolean changeOccurred = editor.set("/path/in/document", "value");

if (changeOccurred) {

    editor.save();
}
else {

  //
  // the value we're trying to set is identical with the value present in the file, react accordingly 
  //
  
}

The modification preserves the original format, nothing is modified except the value that is being changed.

The editor can be also used to read values:

File file = ...;
InLineXmlEditor editor = new InLineXmlEditor(file);

String value = editor.get("/path/in/document");

Thread Safety

As per novaordis-utilities 4.2.1, the implementation is NOT thread safe, the editor must be accessed and used from a single thread at a time.