<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jul 28, 2014, at 6:54 AM, Lion Krischer &lt;<a href="mailto:krischer@geophysik.uni-muenchen.de">krischer@geophysik.uni-muenchen.de</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi all,<br><br>leaving the greater issues aside: why not just force the location code to have a certain form with a regex in the schema?<br></blockquote><div><br></div><div>Hi Lion,</div><div><br></div><div>We should definately add the rules to the schema, we just need to decide what they are!</div><br><blockquote type="cite">The following group will match any uppercase alphanumeric two letter code and two spaces:<br><br>^([A-Z0-9]{2}| &nbsp;)$<br><br>It matches “AA”, “00”, “10”, “A1”, “ &nbsp;“ , …<br>but not “—“, “”, “-“, “a1”, ...<br><br>Everything else will get rejected. Then one can be sure that it is consistent everywhere (assuming people test their web services against the schema which is a good idea in any case). Similar regexes should also be defined for the network, station, and channel codes to assure compatibility with SEED. In general it would be a good idea to have the schema enforce as many things as possible and leave little to no room for interpretations.<br><br><br>Now whether one uses two spaces, two dashes, an empty string or what not for an empty location code does not really matter. All are syntactically valid XML and thus any parser can be expected to be able to deal with them. Consistency is by far the most important thing in my opinion. So best choose one and force it with the schema. This will reduce errors and misinterpretations in the long run.<br><br>In terms of existing StationXML parsers I assume most are just stripping whitespaces from the location code and thus “” &nbsp;and “ &nbsp;“ should already work resulting in minimal disruption in the users’ workflows.</blockquote><div><br></div><div>Actually, this does not appear to be happening, in the parsers I’ve used the whitespaces are not stripped. &nbsp;I have read through the XML specifications until my eyes were crossed to try and understand why this would be the case. &nbsp;Then I wrote some test cases and observed no trimming, see test data and code below. &nbsp;Perhaps this attribute is CDATA for some reason? &nbsp;I think we are stuck with the fact that empty string and two spaces are different.</div><div><br></div><div>Has anyone observed this automatic trimming on any system?</div><br><blockquote type="cite"> “--“ would require software to be updated and looks a little bit weird in my opinion and unsuspecting users might interpret it as an invalid location code.<br></blockquote><div><br></div><div>Yes, it would require software changes, the question is would what we gain be worth it. &nbsp;Maybe it looks a little weird, but it is already becoming synonymous in the minds of many because "--" is used for <b>selecting</b>&nbsp;the empty SEED location IDs.</div><div><br></div><div>Chad</div><div><br></div><div><br></div><div>PS. &nbsp;here is my test data:</div><div><br></div><div>------- chan.xml</div><div><div style="margin: 0px; font-family: Monaco;">&lt;FDSNStationXML schemaVersion="1.0"&gt;</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&lt;Channel locationCode="&nbsp; " startDate="2012-03-12T20:28:00" restrictedStatus="open" endDate="2599-12-31T23:59:59" code="BHZ"&gt;</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&lt;/Channel&gt;</div><div style="margin: 0px; font-family: Monaco;">&lt;/FDSNStationXML&gt;</div></div><div>-------</div><div><br></div><div>Here is a test with Python:</div><div>-------</div><div><div style="margin: 0px; font-family: Monaco;">from xml.etree import ElementTree</div><div style="margin: 0px; font-family: Monaco; min-height: 16px;"><br></div><div style="margin: 0px; font-family: Monaco;">with open('chan.xml', 'rt') as f:</div><div style="margin: 0px; font-family: Monaco;">&nbsp; &nbsp; tree = ElementTree.parse(f)</div><div style="margin: 0px; font-family: Monaco; min-height: 16px;"><br></div><div style="margin: 0px; font-family: Monaco;">node = tree.find('./with_attributes')</div><div style="margin: 0px; font-family: Monaco;">print node.tag</div><div style="margin: 0px; font-family: Monaco;">for name, value in sorted(node.attrib.items()):</div><div style="margin: 0px; font-family: Monaco;">&nbsp; &nbsp; print '&nbsp; %-4s = "%s"' % (name, value)</div></div><div>-------</div><div><br></div><div>which produces:</div><div>-------</div><div><div style="margin: 0px; font-family: Monaco;">Channel</div><div style="margin: 0px; font-family: Monaco;">&nbsp; code = "BHZ"</div><div style="margin: 0px; font-family: Monaco;">&nbsp; endDate = "2599-12-31T23:59:59"</div><div style="margin: 0px; font-family: Monaco;">&nbsp; locationCode = "&nbsp; "</div><div style="margin: 0px; font-family: Monaco;">&nbsp; restrictedStatus = "open"</div><div style="margin: 0px; font-family: Monaco;">&nbsp; startDate = "2012-03-12T20:28:00"</div></div><div>-------</div><div><br></div><div>No trimming.</div><div><br></div><div>Here is a test with Perl:</div><div>-------</div><div><pre class="POD_VERBATIM">use strict;
use warnings;
use XML::Simple;
use Data::Dumper;

my $file = 'chan.xml';

my $test_data = XMLin($file);</pre><pre class="POD_VERBATIM">print Dumper($test_data);
</pre></div><div>-------</div><div><br></div><div>which produces:</div><div>-------</div><div><div style="margin: 0px; font-family: Monaco;">$VAR1 = {</div><div style="margin: 0px; font-family: Monaco;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'schemaVersion' =&gt; '1.0',</div><div style="margin: 0px; font-family: Monaco;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Channel' =&gt; {</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'locationCode' =&gt; '&nbsp; ',</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'endDate' =&gt; '2599-12-31T23:59:59',</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'restrictedStatus' =&gt; 'open',</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'startDate' =&gt; '2012-03-12T20:28:00',</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'code' =&gt; 'BHZ'</div><div style="margin: 0px; font-family: Monaco;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-family: Monaco;">&nbsp; &nbsp; &nbsp; &nbsp; };</div></div><div>-------</div><div><br></div><div>No trimming.</div><div><br></div><div>There are many more parsing options for Perl and Python and other languages of course, but this is pretty basic stuff. &nbsp; It is how a user such as myself would go about parsing and using StationXML.</div></div></body></html>