gaglioppo
05-06-2006, 09:53
ciao amici,
ho creat questo file .xml
<?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>
e ho creato questo file .dtd di cui ho molti dubbi:
<?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)>
]>
innanzittutto vorrei conferma di non avere fatto errori, mille grazie.
Secondo punto, ho cercato di leggere il file .xml in java:
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();
}
}
}
ma purtroppo, se considera il .dtd mi da il seguente errore:
[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
Terzo, in pratica io dovrei prima crearlo da java il file .xml, poi leggerlo e successivamente modificarlo (cambiare i valori all'interno dei nodi)
Grazie mille a tutti per l'aiuto
ho creat questo file .xml
<?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>
e ho creato questo file .dtd di cui ho molti dubbi:
<?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)>
]>
innanzittutto vorrei conferma di non avere fatto errori, mille grazie.
Secondo punto, ho cercato di leggere il file .xml in java:
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();
}
}
}
ma purtroppo, se considera il .dtd mi da il seguente errore:
[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
Terzo, in pratica io dovrei prima crearlo da java il file .xml, poi leggerlo e successivamente modificarlo (cambiare i valori all'interno dei nodi)
Grazie mille a tutti per l'aiuto