PDA

View Full Version : [java] problema con config.xml


nicolad1988
14-03-2010, 22:29
salve vorrei salvare le impostazioni del mio programma in un file interno al jar.
file config.xml

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<?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>

main

Properties properties = new Properties();
InputStream fis = getClass().getResourceAsStream ("/config.xml");
try {
properties.loadFromXML(fis);
} catch (InvalidPropertiesFormatException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}


errore:

java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at java.util.XMLUtils.load(Unknown Source)
at java.util.Properties.loadFromXML(Unknown Source)
at gui.MindCopy.caricaPreferenze(MindCopy.java:130)
at gui.Mind2.getJFrame(Mind2.java:105)
at gui.Mind2.access$4(Mind2.java:82)
at gui.Mind2$13.run(Mind2.java:695)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPIData(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanPIData(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPI(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at java.util.XMLUtils.getLoadingDoc(Unknown Source)
... 14 more

nicolad1988
15-03-2010, 15:11
help nessuno sà rispondermi:mc:

vladix
15-03-2010, 16:43
il tuo config.xml non e un xml ma un dtd ... cioè la definizione della struttura del xml ... (che tu hai copiato dal sito della sun :D ) ... il tuo xml deve essere composto da un elemento root "properties" con zero o un tag "comment" e zero o più tag "entry" . il tag entry deve avere definito l'attributo key ...


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>commento</comment>
<entry key="property1">value1</entry>
<entry key="property2">value2</entry>
</properties>



Leggiti questo (http://xml.html.it/guide/lezione/1845/dtd-document-type-definition/) tutorial sui dtd.

cmq bastava definire 2,3 proprietà e invocare il metodo "inverso" storeToXML :O

nicolad1988
15-03-2010, 22:33
grazie mille non conosco questo ambito..si può chiudere
:winner: