Hello
I am trying to use the loadFromXML() load a properties file and I don't understand the example because it is not reconizing the dtd.
Is the example I am using wrong?
public static void main(String[] args) throws IOException,
FileNotFoundException, PropertyVetoException, ProfileException, LoginException {
LoadXMLProperties lp =new LoadXMLProperties();
[B]lp.loadXML("ModelResources_1.properties");[/B]
DerbyDAOFactory ddf =new DerbyDAOFactory();
ddf.buildDB();
createJDesktopPane();
XMLReaderComboBox rc = new XMLReaderComboBox();
}
package model.dao;
import java.util.*;
import java.io.*;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
*
* @author depot
*/
public class LoadXMLProperties {
public LoadXMLProperties(){
}
public void loadXML(String path) throws FileNotFoundException, IOException{
Properties prop=new Properties();
FileInputStream fis=new FileInputStream(path);
prop.loadFromXML(fis);
prop.list(System.out);
System.out.println("\nThe XML property: "+prop.getProperty("foo"));
}
}
ModelResources_1.properties in XML format
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE properties SYSTEM "properties.dtd">
<properties>
<comment>Hi</comment>
<entry key="foo">bar</entry>
<entry key="fu">bar</entry>
</properties>
properties.dtd
<!ELEMENT properties ( comment?, entry* ) >
<!ATTLIST properties version CDATA #FIXED "1.0">
<!ELEMENT comment (#PCDATA)>
<!ELEMENT entry (#PCDATA)>
<!ATTLIST entry key CDATA #REQUIRED>
Error
run:
Exception in thread "main" java.util.InvalidPropertiesFormatException: org.xml.sax.SAXException: Invalid system identifier: file:///C:/Users/depot/Documents/ceyesumma/java_cache/my_projects/schooldb_project/target_schooldb/schooldb/schoolofdb/properties.dtd
at java.util.XMLUtils.load(XMLUtils.java:59)
at java.util.Properties.loadFromXML(Properties.java:852)
at model.dao.LoadXMLProperties.loadXML(LoadXMLProperties.java:27)
at view.Main.main(Main.java:36)
Caused by: org.xml.sax.SAXException: Invalid system identifier: file:///C:/Users/depot/Documents/ceyesumma/java_cache/my_projects/schooldb_project/target_schooldb/schooldb/schoolofdb/properties.dtd
at java.util.XMLUtils$Resolver.resolveEntity(XMLUtils.java:174)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:107)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:1018)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1190)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1089)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1002)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:85)
at java.util.XMLUtils.load(XMLUtils.java:57)
... 3 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Thanks