wood burning stoves 2.0*
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
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
Author

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.*;
import java.io.*;

public class LoadSampleXML {
public static void main(String args[]) throws Exception {
Properties prop = new Properties();
FileInputStream fis = new FileInputStream("samplexml.properties");
prop.loadFromXML(fis);
prop.list(System.out);
System.out.println("\nThe foo property: " +
prop.getProperty("project"));
}
}
--------------------------------
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) >

<!ATTLIST entry key CDATA #REQUIRED>

---------------------------------------------
the xml file
---------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "properties.dtd">
<properties>
<comment>Hi</comment>
<entry key="foo">bar</entry>
<entry key="fu">baz</entry>
</properties>
if i am using http://java.sun.com/dtd/properties.dtd
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(XMLUtils.java:59)
at java.util.Properties.loadFromXML(Properties.java:701)
at LoadSampleXML.main(LoadSampleXML.java:8)
Caused by: org.xml.sax.SAXException: Invalid system identifier: file:///D:/util/april1/properties.dtd
at java.util.XMLUtils$Resolver.resolveEntity(XMLUtils.java:174)
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(XMLUtils.java:85)
at java.util.XMLUtils.load(XMLUtils.java:57)
Ilja Preuss
author
Sheriff

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: 1011
    
    3
Short answer
When calling java.util.Properties.loadFromXML(), your XML file is not allowed to specify a DTD other than http://java.sun.com/dtd/properties.dtd.

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.

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

Joined: Mar 16, 2002
Posts: 150
thanks for the clarification
 
 
subject: loadFromXML ---Invalid system identifier error for DTD