• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

loadFromXML(fis)

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks to me like you've declared your DTD to be in the same directory as your XML... at least there's a relative URL in your <!DOCTYPE> declaration, so that's what it means.

But then you went and passed a FileInputStream to the parser. So the parser has no idea where the XML is, so it just looks in your current working directory instead. Which is probably wrong. So just pass a File object to the parser, so it knows where the document is. And do make sure that the DTD and the XML document are in fact in the same directory.

(In future it would be better if you posted formatted code, too. Your post was devilish hard to read.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic