This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "parsing GML using SAXParser" Watch "parsing GML using SAXParser" New topic
Author

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:

<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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: parsing GML using SAXParser
 
Similar Threads
question on mock exam
dtd parsing error
DTD for this XML
Castor Problem Using DTD
question on mock exam