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  loadFromXML ---Invalid system identifier error for DTD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark " loadFromXML ---Invalid system identifier error for DTD" Watch " loadFromXML ---Invalid system identifier error for DTD" New topic

loadFromXML ---Invalid system identifier error for DTD

kamesh aru
Ranch Hand

Joined: Mar 16, 2002
Posts: 150
using loadFromXML in the fallowing programme

import java.util.*;

public class LoadSampleXML {
public static void main(String args[]) throws Exception {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream("");
System.out.println("\nThe foo property: " +
the DTD is
Copyright 2005 Sun Microsystems, Inc. All rights reserved.

<?xml version="1.0" encoding="UTF-8"?>

<!-- DTD for properties -->

<!ELEMENT properties ( comment?, entry* ) >

<!ATTLIST properties version CDATA #FIXED "1.0">

<!ELEMENT comment (#PCDATA) >

<!ELEMENT entry (#PCDATA) >


the xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "properties.dtd">
<entry key="foo">bar</entry>
<entry key="fu">baz</entry>
if i am using
its working fine if given directly properties.xml
throwing errorException in thread "main" java.util.InvalidPropertiesFormatException: org.xml.sax.SAXException: Invalid system identifier: file:///D:/util/april1/properties.dtd
at java.util.XMLUtils.load(
at java.util.Properties.loadFromXML(
at LoadSampleXML.main(
Caused by: org.xml.sax.SAXException: Invalid system identifier: file:///D:/util/april1/properties.dtd
at java.util.XMLUtils$Resolver.resolveEntity(
at org.apache.xerces.util.EntityResolverWrapper.resolveEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.resolveEntity(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at java.util.XMLUtils.getLoadingDoc(
at java.util.XMLUtils.load(
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Moving to XML...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1042
Short answer
When calling java.util.Properties.loadFromXML(), your XML file is not allowed to specify a DTD other than

Long answer
If you look at the source code for java.util.XMLUtils, around line 174 (one of the lines listed in the exception stack trace), you'll see something like...

...where sid is the SYSTEM DTD ID in your XML file's DOCTYPE tag. Obviously, this says that sid MUST be PROPS_DTD_URI or a SAXException will be thrown. Further up in that same file you'll find...

I guess Sun wanted make sure nobody broke their Properties class by using a different DTD.

[ April 05, 2005: Message edited by: Ryan McGuire ]
kamesh aru
Ranch Hand

Joined: Mar 16, 2002
Posts: 150
thanks for the clarification
I agree. Here's the link:
subject: loadFromXML ---Invalid system identifier error for DTD
It's not a secret anymore!