The JMRI XML I/O Servlet provides bidirectional web access to JMRI services.
The servlet lives in the jmri.web.servlet.xmlio
package, and provides web access to the JMRI XML I/O package.
By default, the JMRI Web Server will send any URL that starts with /xmlio
to
this servlet. It will list all known elements of a specified type, accept changes to the
value/state of elements, and respond with current value/state of elements. If sent a list of
elements with current values, it will "monitor" for changes to any of those elements,
returning the new values.
Please note that the XML I/O servlet was only supported with the JMRI Web Server, and may not work with other servlet containers.
The XML schema is defined in the xmlio.xsd schema document.
There is also an attribute-based syntax available (see status examples below). The xmlio server responds with the same syntax used in the request.
Below are some example requests and responses.
<xmlio> <item> <type>turnout</type> <name>IT12</name> </item> <item> <type>sensor</type> <name>West sensor</name> </item> <item> <type>power</type> <name>power</name> </item> </xmlio>Reply:
<xmlio> <item> <type>turnout</type> <name>IT12</name> <value>2</value> </item> <item> <type>sensor</type> <name>West sensor</name> <value>4</value> </item> <item> <type>power</type> <name>power</name> <value>2</value> </item> </xmlio>The "value" element is inserted in the request, and then it's returned as the reply. You can just turn the reply around and use it as another request. If "value" elements are present for all items, the response will only be returned when one or more of the included item's state has changed to something different.
<xmlio> <list> <type>sensor</type> </list> </xmlio>Reply:
<xmlio> <item> <type>sensor</type> <name>IS1</name> <value>2</value> </item> <item> <type>sensor</type> <name>IS2</name> <value>4</value> </item> <item> <type>sensor</type> <name>West sensor</name> <value>2</value> </item> </xmlio>The response can be turned around and used as the next request.
<xmlio> <item> <type>turnout</type> <name>IT12</name> <set>2</set> </item> </xmlio>Reply:
<xmlio> <item> <type>turnout</type> <name>IT12</name> <value>2</value> </item> </xmlio>The "set" element in the request results in the state being set to the given value, and then it's returned in the reply as a value element with the proper value at that point.
All writes are done before the values are collected for any reads, but there is no guarantee that the consequences of the writes have propagated completely.
<turnout name="IT12" set="2" />Reply:
<turnout name="IT12" value="2" />
<xmlio> <throttle> <address>1234</address> <speed>0.75</speed> <forward>true</forward> <F3>false</F3> </throttle> </xmlio>A throttle element is returned unchanged.