Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parsing GML using SAXParser

 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I am having problems parsing GML using SAX. GML unfortunately uses
lots of semi-colons to describe inherent elements contained in the GML files. Here is a snippet of GML data:

<Town>
<gml:featureMember>
<Church fid="c1">
<showName>Chapel</showName>
<gml escription>Chapel in the Convent Grounds</gml escription>
<gml:location>
<gml oint>
<gml:coord>
<gml:X>75</gml:X>
<gml:Y>112</gml:Y>
</gml:coord>
</gml oint>
</gml:location>
</Church>
</gml:featureMember>
</Town>

My dtd is set up as follows:

<?xml version='1.0' encoding='utf-8'?>
<!-- DTD for a simple "XML recording". -->

<!ELEMENT Town (gml:featureMember+)>
<!ELEMENT gml:featureMember (Church+)>
<!ELEMENT Church (showName*, gml escription*, gml:location*)>
<!ELEMENT showName (#PCDATA)>
<!ELEMENT gml escription (#PCDATA)>
<!ELEMENT gml:location (gml oint+)>
<!ELEMENT gml oint (gml:coord+)>
<!ELEMENT gml:coord (gml:X, gml:Y)>
<!ELEMENT gml:X (#PCDATA)>
<!ELEMENT gml:Y (#PCDATA)>

There is no problem here as I have been working with XML for quite some time now. However, when I run my code I encounter the folowing error which results from having semi-colons in the dtd:

org.xml.sax.SAXParseException: Undeclared prefix in name: "gml:featureMember".

This error results from the : contained in gml:featureMember. Does anybody now a convenient way to counter this problem. Thanks a lot. Joe
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried calling setNamespaceAware(false) and setValidating(false) on the SAXParserFactory you get your SAXParser from? Although I doubt that'll help since these should be false by default.
 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lasse. That now works perfectly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic