2

我试图从我的 xml 文件中获取空值,如下所示

  <top:kadastroParselFeature gml:id="KADASTRO_PARSEL.1">
    <top:olcek xsi:nil="true" />
  </top:kadastroParselFeature>

但是我的解析器抛出了这样一个异常:

java.lang.RuntimeException: Parsing failed for kadastroParselFeature: java.lang.NullPointerException
at org.geotools.xml.impl.ParseExecutor.visit(ParseExecutor.java:164)
at org.geotools.xml.impl.BindingWalker$BindingExecutionChain.execute(BindingWalker.java:220)
at org.geotools.xml.impl.BindingWalker.walk(BindingWalker.java:186)
at org.geotools.xml.impl.ElementHandlerImpl.endElement(ElementHandlerImpl.java:236)
at org.geotools.xml.impl.ParserHandler.endElement(ParserHandler.java:719)

我的解析器配置是这样的:

   org.geotools.xml.Configuration configuration = new org.geotools.gml2.GMLConfiguration();

   org.geotools.xml.Parser parser = new org.geotools.xml.Parser( configuration );

   parser.setFailOnValidationError(false);

   HashMap<Object, Object> parsedMap = (HashMap<Object, Object>) parser.parse( isx);

如果我xsi:nill="true"从元素中删除它返回 ""(空字符串) 但我需要 null 。

在http://docs.geotools.org/stable/userguide/library/xml/geometry.html有我的解析器的用法

4

1 回答 1

1

如果我将版本从 gml2 更改为 gml3,则我的工作在我的 gml writer 版本中找到了一个解决方案,但问题没有出现。我改变了我的解析器配置。像这样

       org.geotools.xml.Configuration configuration = new org.geotools.gml3.ApplicationSchemaConfiguration("sampleURL", "sample.xsd");


       org.geotools.xml.Parser parser = new org.geotools.xml.Parser( configuration );
于 2014-12-23T08:48:46.583 回答