File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loadFromXML ---Invalid system identifier error for DTD

 
kamesh aru
Ranch Hand
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to XML...
 
Ryan McGuire
Ranch Hand
Posts: 1048
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the clarification
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic