[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

XML problem

If my program try to parse a xml file which starts with
<?xml version="1.0"?>
<!DOCTYPE symbolDefinition SYSTEM "C:\symbol.dtd">    
it gives an error. The program works fine if the xml file starts with
<?xml version="1.0"?>
<!DOCTYPE symbolDefinition SYSTEM "symbol.dtd">
.
The error says its something to do with URI but I don't know how to over come this problem. The file "symbol.dtd" exists in the correct directory.

the following is the code to parse XML files.

Thanx



DocumentBuilderFactory factory
              = DocumentBuilderFactory.newInstance();
          factory.setValidating(true);
          factory.setIgnoringElementContentWhitespace(true);
          DocumentBuilder builder = factory.newDocumentBuilder();
     Document doc = builder.parse(zin);


0
asukai
Asked:
asukai
  • 3
  • 2
1 Solution
 
girionisCommented:
 Can you post the exact error messages and the versoin of XML parser you are using? Latest versions of Xerces have problems with paths since the expect everything to be a URI.
0
 
asukaiAuthor Commented:
It's rather long error
org.xml.sax.SAXParseException: Relative URI "C:\symbol.dtd"; can not be reso
lved without a base URI.
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3176)
        at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2758)
        at org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2730)
        at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1129)

        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
        at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

        at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl
.java:185)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:76)
        at XMLParser.<init>(XMLParser.java:62)
        at DesktopFrame.actionPerformed(DesktopFrame.java:814)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
64)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1817)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:419)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1
109)
        at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseRelease
d(BasicMenuItemUI.java:943)
        at java.awt.Component.processMouseEvent(Component.java:5093)
        at java.awt.Component.processEvent(Component.java:4890)
        at java.awt.Container.processEvent(Container.java:1566)
        at java.awt.Component.dispatchEventImpl(Component.java:3598)
        at java.awt.Container.dispatchEventImpl(Container.java:1623)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
        at java.awt.Container.dispatchEventImpl(Container.java:1609)
        at java.awt.Window.dispatchEventImpl(Window.java:1585)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
java.lang.NullPointerException
        at XMLParser.getSymbols(XMLParser.java:157)
        at DesktopFrame.actionPerformed(DesktopFrame.java:815)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
64)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1817)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:419)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257
)
        at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
        at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1
109)
        at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseRelease
d(BasicMenuItemUI.java:943)
        at java.awt.Component.processMouseEvent(Component.java:5093)
        at java.awt.Component.processEvent(Component.java:4890)
        at java.awt.Container.processEvent(Container.java:1566)
        at java.awt.Component.dispatchEventImpl(Component.java:3598)
        at java.awt.Container.dispatchEventImpl(Container.java:1623)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
        at java.awt.Container.dispatchEventImpl(Container.java:1609)
        at java.awt.Window.dispatchEventImpl(Window.java:1585)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
0
 
girionisCommented:
 It expects the location of the dtd file under the relative URI of your application. Try to use an absolute URI by doing:

  <!DOCTYPE symbolDefinition SYSTEM "file://C/symbol.dtd">

  and tell us what happens. Your SAX implementation parser should be able to resolve it this time.
0
 
asukaiAuthor Commented:
Isn't it
<!DOCTYPE symbolDefinition SYSTEM "file://C:/symbol.dtd">

?
0
 
girionisCommented:
 Hmm... I think it is without the ":". Try it with both and see if it works.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now