F
Fabio
Hi,
I like to validate a XML-Document-Instance (below =doc).
/**********************java-Code*************************
*********************************************************
*/
DocumentBuilderFactory dbf=null;
Document doc=null;
dbf = DocumentBuilderFactory.newInstance();
DOMParser dp=new DOMParser();
DocumentBuilder db=null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e2) {
// TODO Automatisch erstellter Catch-Block
e2.printStackTrace();
}
doc=db.newDocument();
Element e=doc.createElementNS("xsi","root" );
Attr at=doc.createAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi");
at.setNodeValue("http://www.w3.org/2001/XMLSchema-instance");
Attr schLoc=doc.createAttributeNS("anyXMLSchema.xsd","xsi:noNamespaceSchemaLocation");
schLoc.setNodeValue("anyXMLSchema.xsd");
Element e1=doc.createElement("child");
e1.appendChild(doc.createTextNode("12"));
e.setAttributeNodeNS(at);
e.setAttributeNodeNS(schLoc);
e.appendChild(e1);
// doc-Instance
doc.appendChild(e);
/************************JAVA-Code end*******************
*********************************************************
*/
my first problem is i can't use jdk 1.5
I found this below code from apache.org from Example DOM3.java
/***********************JAVA-Code**************************
*********************************************************
*/
..........
// set error handler on the Document
config = doc.getDomConfig(); // <-- can't use this method
config.setParameter("error-handler", errorHandler);
// set validation feature
config.setParameter("validate", Boolean.TRUE);
config.setParameter("schema-type",
"http://www.w3.org/2001/XMLSchema");
config.setParameter("schema-location","data/personal.xsd");
// remove comments from the document
config.setParameter("comments", Boolean.FALSE);
System.out.println("Normalizing document... ");
doc.normalizeDocument();
.....
/**********************JAVA-Code end*********************
*********************************************************
*/
But it not functioned
Can somebody give me a example, for validating a Doc-Instance with
a XML-Schema ???????????????
thank a lot
I like to validate a XML-Document-Instance (below =doc).
/**********************java-Code*************************
*********************************************************
*/
DocumentBuilderFactory dbf=null;
Document doc=null;
dbf = DocumentBuilderFactory.newInstance();
DOMParser dp=new DOMParser();
DocumentBuilder db=null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e2) {
// TODO Automatisch erstellter Catch-Block
e2.printStackTrace();
}
doc=db.newDocument();
Element e=doc.createElementNS("xsi","root" );
Attr at=doc.createAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi");
at.setNodeValue("http://www.w3.org/2001/XMLSchema-instance");
Attr schLoc=doc.createAttributeNS("anyXMLSchema.xsd","xsi:noNamespaceSchemaLocation");
schLoc.setNodeValue("anyXMLSchema.xsd");
Element e1=doc.createElement("child");
e1.appendChild(doc.createTextNode("12"));
e.setAttributeNodeNS(at);
e.setAttributeNodeNS(schLoc);
e.appendChild(e1);
// doc-Instance
doc.appendChild(e);
/************************JAVA-Code end*******************
*********************************************************
*/
my first problem is i can't use jdk 1.5
I found this below code from apache.org from Example DOM3.java
/***********************JAVA-Code**************************
*********************************************************
*/
..........
// set error handler on the Document
config = doc.getDomConfig(); // <-- can't use this method
config.setParameter("error-handler", errorHandler);
// set validation feature
config.setParameter("validate", Boolean.TRUE);
config.setParameter("schema-type",
"http://www.w3.org/2001/XMLSchema");
config.setParameter("schema-location","data/personal.xsd");
// remove comments from the document
config.setParameter("comments", Boolean.FALSE);
System.out.println("Normalizing document... ");
doc.normalizeDocument();
.....
/**********************JAVA-Code end*********************
*********************************************************
*/
But it not functioned
Can somebody give me a example, for validating a Doc-Instance with
a XML-Schema ???????????????
thank a lot