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?
[code]public static void main(String[] args) throws
IOException,
FileNotFoundException, PropertyVetoException,
ProfileException, LoginException {
LoadXMLProperties lp =new LoadXMLProperties();
lp.loadXML("ModelResources_1.properties");
DerbyDAOFactory ddf =new DerbyDAOFactory();
ddf.buildDB();
createJDesktopPane();
XMLReaderComboBox rc = new XMLReaderComboBox();
} [/code]
[code]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"));
}
}[/code]
[b]ModelResources_1.properties in XML format[/b]
[code]<?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>[/code]
[b]properties.dtd[/b]
[code]<!ELEMENT properties ( comment?, entry* ) >
<!ATTLIST properties version CDATA #FIXED "1.0">
<!ELEMENT comment (#PCDATA)>
<!ELEMENT entry (#PCDATA)>
<!ATTLIST entry key CDATA #REQUIRED>
[/code]
[b]Error[/b]
[code]run:
Exception in thread "main"
java.util.InvalidPropertiesFormatException:
org.xml.sax.SAXException: Invalid system identifier:
file:///C:/Users/depot/Documents/ceyesumma/java_cache/my_project
s/schooldb_project/target_schooldb/schooldb/schoolofdb/propertie
s.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_project
s/schooldb_project/target_schooldb/schooldb/schoolofdb/propertie
s.dtd
at
java.util.XMLUtils$Resolver.resolveEntity(XMLUtils.java:174)
at
com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.re
solveEntity(EntityResolverWrapper.java:107)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolve
EntityAsPerStax(XMLEntityManager.java:1018)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$D
TDDriver.dispatch(XMLDocumentScannerImpl.java:1190)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$D
TDDriver.next(XMLDocumentScannerImpl.java:1089)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$P
rologDriver.next(XMLDocumentScannerImpl.java:1002)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.n
ext(XMLDocumentScannerImpl.java:648)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScann
erImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.pa
rse(XML11Configuration.java:807)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.pa
rse(XML11Configuration.java:737)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLPa
rser.java:107)
at
com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMPa
rser.java:225)
at
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.pars
e(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)[/code]
Thanks