|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Sep 2002
Città: Monza
Messaggi: 598
|
[xml e poi java] validazione sbagliata? e poi lettura/scrittura in java
ciao amici,
ho creat questo file .xml Codice:
<?xml version="1.0" standalone="no"?> <!DOCTYPE fileConfig SYSTEM "config.dtd"> <configurazione> <nome> modello </nome> <tipo> CLASSICO </tipo> <url> http://qualcosa.it </url> <passo> <xpath> html/body/form/table/tr[1]/td[2]/\#text/ </xpath> <tipo> PDB </tipo> <condizioni> <condizione> <xpath> html/body/form/table/tr[1]/td[2]/\#text/ </xpath> <operatore> > </operatore> <valore> 1e-03 </valore> </condizione> </condizioni> </passo> </configurazione> Codice:
<?xml version="1.0" encoding="iso-8859-1"> <!DOCTYPE configurazione (passo+)[ <!ELEMENT nome (#PCDATA)> <!ELEMENT tipo (classico | emailAllegato | emailTesto | emailLink)> <!ELEMENT url (#PCDATA)> <!ELEMENT passo (xpath,tipo,condizioni*)> <!ELEMENT condizioni (condizione+)> <!ELEMENT condizione (xpath,operatore,valore)> ]> Secondo punto, ho cercato di leggere il file .xml in java: Codice:
import java.io.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
public class Loadxml
{
static Document node2;
public static void main(String argv[])
{
String xmlFile = "configurazione.xml";
DOMParser parser = new DOMParser();
try {
parser.parse(xmlFile);
}
catch (IOException ioe) { ioe.printStackTrace(); } catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Node node = parser.getDocument();
stampa(node,">");
}
public static void stampa(Node node,String prefi){
String nome=""+node.getNodeName();
String prefisso="-"+prefi;
System.out.println(prefisso+" "+nome);
Node child = node.getFirstChild();
while (child != null) {
stampa(child,prefisso);
child = child.getNextSibling();
}
}
}
Codice:
[Fatal Error] config.dtd:1:42: A pseudo attribute name is expected. org.xml.sax.SAXParseException: A pseudo attribute name is expected. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at wrapperFDS.Loadxml.main(Loadxml.java:20) -> #document --> fileConfig Grazie mille a tutti per l'aiuto
__________________
Nunc est bibendum |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:53.



















