on 10-01-2010 7:19 AM
Hi,
I have a JAVA program:
package dTDValidate;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.validation.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
public class DTDValidateXML {
public static void main(String args[]) {
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
//Ignore the fatal errors
public void fatalError(SAXParseException exception)throws SAXException { }
//Validation errors
public void error(SAXParseException e)throws SAXParseException {
System.out.println("Error at " +e.getLineNumber() + " line.");
System.out.println(e.getMessage());
System.exit(0);
}
//Show warnings
public void warning(SAXParseException err)throws SAXParseException{
System.out.println(err.getMessage());
System.exit(0);
}
});
Document xmlDocument = builder.parse(new FileInputStream("Employee.xml"));
DOMSource source = new DOMSource(xmlDocument);
StreamResult result = new StreamResult(System.out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "Employee.dtd");
transformer.transform(source, result);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
I have some queries about the above code:
I have output structure as:
<Receivers>
<Receiver>
<Party>
</agency>
</scheme>
</Service>
</Receiver
</Receivers>
1) What modification should be made to the above code to ensure so that the correct Receiver Service is populated by the above JAVA code as per the output.
For example:
If no validation error, Service should be Service1
If validation error, Party should be Party1 and Service should be Service2
Please help.
Thank you,
Pankaj.
Closing the Thread.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.