I’m generating some xml files that needs to conform to an xsd file that was given to me. How should I verify they conform?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Java runtime library supports validation. Last time I checked this was the Apache Xerces parser under the covers. You should probably use a javax.xml.validation.Validator.
The schema factory constant is the string
http://www.w3.org/2001/XMLSchemawhich defines XSDs. The above code validates a WAR deployment descriptor against the URLhttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsdbut you could just as easily validate against a local file.You should not use the DOMParser to validate a document (unless your goal is to create a document object model anyway). This will start creating DOM objects as it parses the document – wasteful if you aren’t going to use them.