File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes parsing GML using SAXParser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "parsing GML using SAXParser" Watch "parsing GML using SAXParser" New topic

parsing GML using SAXParser

joe weakers
Ranch Hand

Joined: May 31, 2004
Posts: 38
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:

<Church fid="c1">
<gml escription>Chapel in the Convent Grounds</gml escription>
<gml oint>
</gml oint>

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)>

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

Joined: Jan 23, 2002
Posts: 11962
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.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
joe weakers
Ranch Hand

Joined: May 31, 2004
Posts: 38
Thanks Lasse. That now works perfectly
I agree. Here's the link:
subject: parsing GML using SAXParser
It's not a secret anymore!