Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

expecting system identifier

Hi all,

 

        i am trying to parse a xml file that hosts at the web server. am dom parser for this purpose. while doing this, when i connect for the first time it is giving an error of "expecting system identifier". i found this is occuring during parsing of the xml file, and is a SAXParseException. and more surprisingly when am running this for the second time onwords it is working fine. no errors and parsing is also going fine. 

 

 

how  can i fix this and why am getting this error. this is my code snippet. 

try{ factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); conn = (HttpConnection) Connector.open(URL); inputStream = conn.openDataInputStream(); document = builder.parse( inputStream ); rootElement = document.getDocumentElement(); rootElement.normalize(); displayNode(rootElement); }catch (ParserConfigurationException e) { synchronized(Application.getEventLock()){ UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); UiApplication.getUiApplication().pushScreen(new ErrorPage(e.getMessage()+"Parser Error")); } } catch (SAXException e) { synchronized(Application.getEventLock()){ UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); UiApplication.getUiApplication().pushScreen(new ErrorPage(e.getMessage()+"SAX Parsing Error")); // here error is coming for the first time only. } } catch (IOException e) { synchronized(Application.getEventLock()){ UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); UiApplication.getUiApplication().pushScreen(new ErrorPage(e.getMessage()+"IO Stream Error")); } }

 

 

 

 

Thanks and Regards,

PraveenGoparaju 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: expecting system identifier

It looks like either your XML has a system DTD or possibly the xml makes references to other XML by way of namespaces or something. My XML is a little rusty but I am very familiar with these problems. Enough to know that giving a systemId to the parser can typically solve them. Use the parse that accepts a system URI. If the XML is loaded from "http://myserver.com/context/myfile.xml then give your parse method a second parameter of "http://myserver.com/context/". The web server also has to be configured such that relative paths can be retrieved correctly. In other words if the XML references another file like "./dtds/supporting.dtd" then the server should return this file when asked for "http://myserver.com/context/dtds/supporting.dtd" or else you may continue to see this or other similar errors. My guess is that the XML file's DTD is declared using system notation and second time you try to parse the same file the parser picks up at the text just after the DTD (where the XML begins). You might also want to call setValidating(false) on your DocumentBuilderFactory to prevent it from trying to look up DTDs. However I can't remember how this affects DTDs that include other files. It's been a while since I was serious in XML.
Highlighted
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: expecting system identifier

Hi cliff76,

 

              thankful for your detailed explanation. am getting the xml file as webservice which is of the following form. 

    http://myserver/project/Services/abc.asmx/abcd. for these kind of urls how to give the system id??

 

              If i have the xml file without DTDs, then can i solve this issue. I tried with setValidating(false) on DocumentBuilderFactory, but i didnt find any improvement. 

 

 

Thanks and Regards,

PraveenGoparaju.  

Thanks and Regards,
PraveenGoparaju.