Problem while parsing alerts from alerts.weather.gov

61 views
Skip to first unread message

Rogelio Alejandro Ortiz Sevilla

unread,
Nov 21, 2011, 5:41:29 PM11/21/11
to CAP Library
Good day everyone:

Please forgive me if this is not the right place to ask. I just didn't
find a place to post my questions but here.

I'm currently using your library to handle Cap Alerts (works very
well). I have only one problem. When I create a new CapXmlParser
object with validation turned on, and then, try to parse any alert
from the NOAA site (http://alerts.weather.gov/cap/us.php?x=0).I get
the following exception:


cvc-pattern-valid: Value '' is not facet-valid with respect to pattern
'\s*[^\s,&<]+,[^\s,&<]+,\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d[-,+]\d\d:\d
\d(\s+[^\s,&<]+,[^\s,&<]+,\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d[-,+]\d\d:\d
\d)*\s*' for type '#AnonType_referencesalert'.; cvc-type.3.1.3: The
value '' of element 'references' is not valid.

If I understand correctly, the xsd is requiring a value on the
references tag. If no references are intended, the <references> tag
must not be included. However, the NOAA site is throwing alerts with
empty value <references> tag.

My question is: how can I enable the google cap library to handle the
NOAA alerts without having to turn off the validation??


Thanks a lot in advance.

Steve Hakusa

unread,
Nov 21, 2011, 7:20:33 PM11/21/11
to cap-libra...@googlegroups.com
Hi Rogelio,

You're right.  The CAP alerts currently being produced by NOAA at http://alerts.weather.gov/cap/us.php?x=0 are not valid CAP.  They are fixing this in their CAP 1.2 implementation (wiki).

I have an uncommitted change that adds a version of parseFrom that will return parse errors instead of throwing them in a CapException.



Then you can work around the problem by catching and ignoring the error, something like:

    for (CapException.Reason reason : new XercesCapExceptionMapper().map(reasons)) {
      if (reason.getType() == CapException.Type.INVALID_REFERENCES) {
        if (capAlert.getReferences().getValueCount() == 0) {
          continue;
        }
      }
      unhandled.add(reason);
    }
    if (!unhandled.isEmpty()) {
      throw new CapException(unhandled);
    }

I'll try to get that change committed in the next day or so.  I'm glad you are finding the library to be useful.

Steve
Reply all
Reply to author
Forward
0 new messages