Files
JIMRI/help/en/html/web/XMLIO.shtml
T
2026-06-17 14:00:51 +02:00

271 lines
8.7 KiB
Plaintext

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="generator" content="HTML Tidy for HTML5 for Apple macOS version 5.8.0">
<!-- Copyright 2015 -->
<title>JMRI: XML I/O Servlet - no longer supported</title><!--#include virtual="/help/en/parts/Style.shtml" -->
</head>
<body>
<!--#include virtual="/help/en/parts/Header.shtml" -->
<div id="mBody">
<!--#include virtual="Sidebar.shtml" -->
<div id="mainContent">
<h1>JMRI: XML I/O Servlet - no longer supported</h1>
<strong>The XML I/O protocol was removed from JMRI in the 3.11 development
cycle.</strong><br>
Affected applications should be ported to using the <a href="JsonServlet.shtml">JSON
protocol</a>.<br>
This page is only for reference of older versions.
<p>The JMRI XML I/O Servlet provides bidirectional web access to JMRI services.</p>
<p>The servlet lives in the <a href=
"https://jmri.org/JavaDoc/doc/jmri/web/servlet/xmlio/package-summary.html">jmri.web.servlet.xmlio</a>
package, and provides web access to the <a href=
"https://jmri.org/JavaDoc/doc/jmri/web/xmlio/package-summary.html">JMRI XML I/O package</a>.
By default, the JMRI Web Server will send any URL that starts with <code>/xmlio</code> 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.</p>
Element types fully supported:
<ul>
<li>power</li>
<li>turnout</li>
<li>sensor</li>
<li>signalhead</li>
<li>signalmast</li>
<li>memory</li>
<li>route</li>
</ul>
Element types list-only:
<ul>
<li>roster</li>
<li>frame</li>
<li>panel</li>
<li>metadata</li>
<li>railroad</li>
</ul>
Throttle is a unique case, with a slightly different syntax, supporting read and change, but
not list or monitoring:
<ul>
<li>throttle</li>
</ul>
There are several sample pages that (used to) show how this can be used:
<dl>
<dt>
<a href="http://localhost:12080/web/request.html">web/request.html</a>
</dt>
<dd>Makes a single XML request for all available sensors, and shows their status in a
table.</dd>
<dt>
<a href="http://localhost:12080/web/monitor.html">web/monitor.html</a>
</dt>
<dd>Uses delayed requests to monitor the status of all sensors, updating a table when any
change.</dd>
<dt>
<a href="http://localhost:12080/web/throttle.html">web/throttle.html</a>
</dt>
<dd>Sends a speed command to a DCC locomotive on the layout when a button is pressed.</dd>
<dt>
<a href="http://localhost:12080/web/turnoutPanel.html">web/turnoutPanel.html</a>
</dt>
<dd>Example of a control panel on a web page.</dd>
<dt>
<a href="http://localhost:12080/web/turnoutMonitor.html">web/turnoutMonitor.html</a>
</dt>
<dd>More complex turnout table, with buttons to throw and close turnouts.</dd>
<dt>
<a href="http://localhost:12080/web/JMRI_XMLIO_test.html">web/JMRI_XMLIO_test.html</a>
</dt>
<dd>Useful for sending various commands to xmlio server and viewing the responses.</dd>
<dt>
<a href="http://localhost:12080/web/JMRIMobile.html">web/JMRIMobile.html</a>
</dt>
<dd>This tool uses the xmlio server for retrieving data from JMRI, sending changes and
monitoring for changes to elements.</dd>
</dl>
<p>Please note that the XML I/O servlet was only supported with the <a href=
"index.shtml">JMRI Web Server</a>, and may not work with other servlet containers.</p>
<h2>Request Format</h2>
<p>The XML schema is defined in the <a href="https://jmri.org/xml/schema/xmlio.xsd">xmlio.xsd
schema document</a>.</p>
<p>There is also an attribute-based syntax available (see status examples below). The xmlio
server responds with the same syntax used in the request.</p>
<p>Below are some example requests and responses.</p>
<h3>Get the status of individual objects</h3>
Request:
<pre style="font-family: monospace;">
&lt;xmlio&gt;
&lt;item&gt;
&lt;type&gt;turnout&lt;/type&gt;
&lt;name&gt;IT12&lt;/name&gt;
&lt;/item&gt;
&lt;item&gt;
&lt;type&gt;sensor&lt;/type&gt;
&lt;name&gt;West sensor&lt;/name&gt;
&lt;/item&gt;
&lt;item&gt;
&lt;type&gt;power&lt;/type&gt;
&lt;name&gt;power&lt;/name&gt;
&lt;/item&gt;
&lt;/xmlio&gt;
</pre>Reply:
<pre style="font-family: monospace;">
&lt;xmlio&gt;
&lt;item&gt;
&lt;type&gt;turnout&lt;/type&gt;
&lt;name&gt;IT12&lt;/name&gt;
&lt;value&gt;2&lt;/value&gt;
&lt;/item&gt;
&lt;item&gt;
&lt;type&gt;sensor&lt;/type&gt;
&lt;name&gt;West sensor&lt;/name&gt;
&lt;value&gt;4&lt;/value&gt;
&lt;/item&gt;
&lt;item&gt;
&lt;type&gt;power&lt;/type&gt;
&lt;name&gt;power&lt;/name&gt;
&lt;value&gt;2&lt;/value&gt;
&lt;/item&gt;
&lt;/xmlio&gt;
</pre>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.
<h3>Get all objects of a type</h3>
Request:
<pre style="font-family: monospace;">
&lt;xmlio&gt;
&lt;list&gt;
&lt;type&gt;sensor&lt;/type&gt;
&lt;/list&gt;
&lt;/xmlio&gt;
</pre>Reply:
<pre style="font-family: monospace;">
&lt;xmlio&gt;
&lt;item&gt;
&lt;type&gt;sensor&lt;/type&gt;
&lt;name&gt;IS1&lt;/name&gt;
&lt;value&gt;2&lt;/value&gt;
&lt;/item&gt;
&lt;item&gt;
&lt;type&gt;sensor&lt;/type&gt;
&lt;name&gt;IS2&lt;/name&gt;
&lt;value&gt;4&lt;/value&gt;
&lt;/item&gt;
&lt;item&gt;
&lt;type&gt;sensor&lt;/type&gt;
&lt;name&gt;West sensor&lt;/name&gt;
&lt;value&gt;2&lt;/value&gt;
&lt;/item&gt;
&lt;/xmlio&gt;
</pre>The response can be turned around and used as the next request.
<h3>Set the status of an object</h3>
Request:
<pre style="font-family: monospace;">
&lt;xmlio&gt;
&lt;item&gt;
&lt;type&gt;turnout&lt;/type&gt;
&lt;name&gt;IT12&lt;/name&gt;
&lt;set&gt;2&lt;/set&gt;
&lt;/item&gt;
&lt;/xmlio&gt;
</pre>Reply:
<pre style="font-family: monospace;">
&lt;xmlio&gt;
&lt;item&gt;
&lt;type&gt;turnout&lt;/type&gt;
&lt;name&gt;IT12&lt;/name&gt;
&lt;value&gt;2&lt;/value&gt;
&lt;/item&gt;
&lt;/xmlio&gt;
</pre>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.
<p>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.</p>
<h3>Set the status of an object (attribute-based syntax)</h3>
Request:
<pre style="font-family: monospace;">
&lt;turnout name="IT12" set="2" /&gt;
</pre>Reply:
<pre style="font-family: monospace;">
&lt;turnout name="IT12" value="2" /&gt;
</pre>
<h3>Control a Throttle</h3>
A &lt;throttle&gt; element can be used to control a DCC Throttle via the default
ThrottleManager. The first use allocates the throttle, and all later ones set any attributes
present:
<pre style="font-family: monospace;">
&lt;xmlio&gt;
&lt;throttle&gt;
&lt;address&gt;1234&lt;/address&gt;
&lt;speed&gt;0.75&lt;/speed&gt;
&lt;forward&gt;true&lt;/forward&gt;
&lt;F3&gt;false&lt;/F3&gt;
&lt;/throttle&gt;
&lt;/xmlio&gt;
</pre>A throttle element is returned unchanged.
<h2>Related Documentation</h2>
<ul>
<li>C.F. K. H. Wolf, K. Froitzheim, M. Weber, Department of Distributed Systems, University
of Ulm, "Interactive Video and Remote Control via the World Wide Web", in "<em>Lecture
Notes in Computer Science</em>", Springer, Berlin, 1996.</li>
<li>Previously in Volume 7, Number 5 of "<em>M&auml;rklin Digital Newsletter</em>", Dr. T.
Catherall Ed, September/October 1995 (<a href=
"http://rr.informatik.tu-freiberg.de/index.php?con=home&amp;sel=&amp;lang=eng&amp;js=1&amp;">project
website no longer online</a>).
</li>
</ul>
<!--#include virtual="/help/en/parts/Footer.shtml" -->
</div>
<!-- closes #mainContent-->
</div>
<!-- closes #mBody-->
<script src="/js/help.js"></script>
</body>
</html>