Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the correct ans from my side for yours which will surely help you out:</p> <p>Firstly the xml which you had was not of proper syntax which i have corrected in here:</p> <pre><code>&lt;TRANSACTIONS xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./transactions.xsd" ASOF_DATE="6/10/2011" CREATE_DATE="6/10/2011" RECORDS="1769"&gt; &lt;TRADE&gt; &lt;ACCRUAL_DT&gt; 09/22/2012 &lt;/ACCRUAL_DT&gt; &lt;COUNTERPARTY_CODE&gt; US &lt;/COUNTERPARTY_CODE&gt; &lt;CUSIP&gt; BRS87R7N9 &lt;/CUSIP&gt; &lt;DESC_INSTMT&gt; CFD COOKSON GROUP PLC &lt;/DESC_INSTMT&gt; &lt;DESK/&gt; &lt;/TRADE&gt; &lt;/TRANSACTIONS&gt; </code></pre> <p>Now simple go to the site: <a href="http://www.freeformatter.com/xsd-generator.html" rel="nofollow">http://www.freeformatter.com/xsd-generator.html</a></p> <p>Enter the XML mentioned above and click Generate XSD Schema. So now the schema would be generated and thereafter save it in your local disk and then run the code below to check and verify it!</p> <pre><code>package your_package name; import java.io.File; import java.io.IOException; import javax.xml.XMLConstants; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.xml.sax.SAXException; public class XMLValidator { public void validate() { File xmlFile = new File(Provide the xml file location (disk) in double quotes); File xsdFile = new File(Provide the xml file location (disk) in double quotes); boolean retStat = this.validateSchema(xmlFile, xsdFile); if(retStat){ System.out.println("Validated"); } else System.out.println("Not Valid"); } private boolean validateSchema(File xml, File xsd){ Schema schema = null; try{ schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(xsd); }catch (SAXException e) { e.printStackTrace(); return false; }catch(Exception fnEx){ fnEx.printStackTrace(); return false; } if(null != schema){ Validator validator = schema.newValidator(); try { validator.validate(new StreamSource(xml)); return true; } catch (SAXException e) { return false; } catch (IOException e) { e.printStackTrace(); } } return false; } public static void main(String args[]){ XMLValidator newObj=new XMLValidator(); newObj.validate(); } </code></pre> <p>}</p> <p>And therby by solved!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload