Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Validation a DOM-Tree (Document-Instance) with a XML-Schema

Reply
Thread Tools

Validation a DOM-Tree (Document-Instance) with a XML-Schema

 
 
Fabio
Guest
Posts: n/a
 
      09-08-2004
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/","xmlnssi");
at.setNodeValue("http://www.w3.org/2001/XMLSchema-instance");
Attr schLoc=doc.createAttributeNS("anyXMLSchema.xsd","x si: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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying a Validation Error in a Validation Summary Control Lucas Tam ASP .Net 2 02-26-2004 07:49 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
Web form validation vs object validation Colin Basterfield ASP .Net 1 11-29-2003 12:10 AM
validation summary doesnt display when there's client-side validation Libs ASP .Net 0 06-25-2003 03:05 PM
Re: only custom validation control does server side validation? Colin Mackay ASP .Net 0 06-25-2003 07:54 AM



Advertisments