Valodate xml against xsd

Hi ,
I have the below as "position.xml"
<?xml version="1.0" encoding="UTF-8"?>
<position
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file://c:\wsad\workspace\sma\xml\position.xsd">
<position_number>12345</position_number>
<position_title>Sr. Engr</position_title>
<report_to_position>23456</report_to_position>
<incumbent>23456</incumbent>
<operation>INSERT</operation>
</position>
and
position.xsd is :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="position" type="positionType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
     <xs:complexType name="positionType">
<xs:sequence>
     <xs:element name="position_number" type="xs:string"/>
<xs:element name="position_title" type="xs:string"/>
     <xs:element name="report_to_position" type="xs:string"/>
     <xs:element name="incumbent"           type="xs:string"/>
     <xs:element name="operation"           type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
When i use the code:
import org.apache.xerces.parsers.DOMParser;
import java.io.File;
public class SchemaTest {
     private String xmlFile = "";
     private String xsdFile = "";
     public SchemaTest(String xmlFile, String xsdFile) {
          this.xmlFile = xmlFile;
          this.xsdFile = xsdFile;
     public static void main(String args[]) {
          for (int i = 0; i < args.length; i++) {
               switch (i) {
                    case 0 :
                         System.out.println("XML File=" + args);
                         break;
                    case 1 :
                         System.out.println("XSD File=" + args);
                         break;
                    default :
                         System.out.println("Unknown=" + args);
                         break;
          if (args.length != 2) {
               System.err.println("Usage: <xml file> <xsd file>");
               System.exit(1);
          SchemaTest testXml = new SchemaTest(args[0], args[1]);
          testXml.process();
     public void process() {
          File docFile = new File(xmlFile);
          try {
               DOMParser parser = new DOMParser();
               parser.setFeature("http://xml.org/sax/features/validation", true);
               parser.setFeature("http://apache.org/xml/features/validation/schema",true);
               parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
//               parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", xsdFile);
               parser.setProperty(
                    "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                    xsdFile);
               ErrorChecker errors = new ErrorChecker();
               parser.setErrorHandler(errors);
               parser.parse(docFile.toString());
          } catch (Exception e) {
               System.out.print("Problem parsing the file.");
               System.out.println("Error: " + e);
I get the following error message:
XML File=[Ljava.lang.String;@45a877
XSD File=[Ljava.lang.String;@45a877
Line 4...
cvc-elt.1: Cannot find the declaration of element 'position'.
Line 4...
cvc-datatype-valid.1.2.1: 'file://c:\wsad\workspace\sma\xml\position.xsd' is not a valid value for 'anyURI'.
Line 4...
cvc-attribute.3: The value 'file://c:\wsad\workspace\sma\xml\position.xsd' of attribute 'xsi:noNamespaceSchemaLocation' on element 'position' is not valid with respect to its type, 'anyURI'.
Can someone help !!!!!!!!
Thanks !

cvc-datatype-valid.1.2.1: 'file://c:\wsad\workspace\sma\xml\position.xsd' is not a valid value for 'anyURI'.I am guessing that's in a place that is supposed to have a URI. Well, if you're going to have backslashes in a URI then you have to escape them as %5C. But if you meant for them to separate directory names, then replace them by slashes as per the URI specification.

Similar Messages

  • How to parse XML against XSD,DTD, etc.. locally (no internet connection) ?

    i've searched on how to parse xml against xsd,dtd,etc.. without the needs of internet connection..
    but unfortunately, only the xsd file can be set locally and still there needs the internet connection for the other features, properties.
    XML: GML file input from gui
    XSD: input from gui
    javax.xml
    package demo;
    import java.io.File;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.xml.XMLConstants;
    import javax.xml.transform.Source;
    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 Sample1WithJavaxXML {
         public static void main(String[] args) {
              URL schemaFile = null;
              try {
                   //schemaFile = new URL("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd");
                   File file0 = new File("AppSchema-C01-v1_0.xsd");
                   schemaFile = new URL(file0.toURI().toString());
              } catch (MalformedURLException e1) {
                   // TODO Auto-generated catch block
                   e1.printStackTrace();
              //Source xmlFile = new StreamSource(new File("web.xml"));
              Source xmlFile = new StreamSource(new File("C01.xml"));
              SchemaFactory schemaFactory = SchemaFactory
                  .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
              //File file1 = new File("XMLSchema.dtd");
              //SchemaFactory schemaFactory = SchemaFactory
                   //.newInstance("javax.xml.validation.SchemaFactory:XMLSchema.dtd");
              Schema schema = null;
              try {
                   schema = schemaFactory.newSchema(schemaFile);
              } catch (SAXException e1) {
                   // TODO Auto-generated catch block
                   e1.printStackTrace();
              Validator validator = schema.newValidator();
              try {
                validator.validate(xmlFile);
                System.out.println(xmlFile.getSystemId() + " is valid");
              } catch (SAXException e) {
                System.out.println(xmlFile.getSystemId() + " is NOT valid");
                System.out.println("Reason: " + e.getLocalizedMessage());
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }Xerces
    package demo;
    import java.io.File;
    import java.util.Date;
    import org.apache.xerces.parsers.DOMParser;
    public class SchemaTest {
         private String xmlFile = "";
         private String xsdFile = "";
         public SchemaTest(String xmlFile, String xsdFile) {
              this.xmlFile = xmlFile;
              this.xsdFile = xsdFile;
         public static void main (String args[]) {
              File file0 = new File("AppSchema-C01-v1_0.xsd");
              String xsd = file0.toURI().toString();
              SchemaTest testXml = new SchemaTest("C01.xml",xsd);
              testXml.process();
         public void process() {
              File docFile = new File(xmlFile);
              DOMParser parser = new DOMParser();
              try {
                   parser.setFeature("http://xml.org/sax/features/validation", true);
                   parser.setFeature("http://apache.org/xml/features/validation/schema", true);
                   parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                             xsdFile);
                   ErrorChecker errors = new ErrorChecker();
                   parser.setErrorHandler(errors);
                   System.out.println(new Date().toString() + " START");
                   parser.parse(docFile.toString());
              } catch (Exception e) {
                   System.out.print("Problem parsing the file.");
                   System.out.println("Error: " + e);
                   System.out.println(new Date().toString() + " ERROR");
                   return;
              System.out.println(new Date().toString() + " END");
    }

    Thanks a lot Sir DrClap..
    I tried to use and implement the org.w3c.dom.ls.LSResourceResolver Interface which is based on the SAX2 EntityResolver.
    please give comments the way I implement it. Here's the code:
    LSResourceResolver Implementation
    import org.w3c.dom.ls.LSInput;
    import org.w3c.dom.ls.LSResourceResolver;
    import abc.xml.XsdConstant.Path.DTD;
    import abc.xml.XsdConstant.Path.XSD;
    public class LSResourceResolverImpl implements LSResourceResolver {
         public LSResourceResolverImpl() {
          * {@inheritDoc}
         @Override
         public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              LSInput input = new LSInputImpl(publicId, systemId, baseURI);
              if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
                   input.setByteStream(classLoader.getResourceAsStream(XSD.XML));
              } else if (XsdConstant.PUBLIC_ID_XMLSCHEMA.equals(publicId)) {
                   input.setByteStream(classLoader.getResourceAsStream(DTD.XML_SCHEMA));
              } else if (XsdConstant.PUBLIC_ID_DATATYPES.equals(publicId)) {
                   input.setByteStream(classLoader.getResourceAsStream(DTD.DATATYPES));
              return input;
    }I also implement org.w3c.dom.ls.LSInput
    import java.io.InputStream;
    import java.io.Reader;
    import org.w3c.dom.ls.LSInput;
    public class LSInputImpl implements LSInput {
         private String publicId;
         private String systemId;
         private String baseURI;
         private InputStream byteStream;
         private String stringData;
         public LSInputImpl(String publicId, String systemId, String baseURI) {
              super();
              this.publicId = publicId;
              this.systemId = systemId;
              this.baseURI = baseURI;
         //getters & setters
    }Then, here's the usage/application:
    I create XMLChecker class (SchemaFactory implementation is Xerces)
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import javax.xml.XMLConstants;
    import javax.xml.stream.FactoryConfigurationError;
    import javax.xml.transform.Source;
    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.ErrorHandler;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import abc.xml.XsdConstant.Path.XSD;
    public class XMLChecker {
         private ErrorMessage errorMessage = new ErrorMessage();
         public boolean validate(String filePath){
              final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              List<Source> schemas = new ArrayList<Source>();
              schemas.add(new StreamSource(classLoader.getResourceAsStream(XSD.XML_SCHEMA)));
              schemas.add(new StreamSource(classLoader.getResourceAsStream(XSD.XLINKS)));
              schemas.add(new StreamSource(classLoader.getResourceAsStream("abc/xml/AppSchema.xsd")));
              SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
              schemaFactory.setResourceResolver(new LSResourceResolverImpl());
              try {
                   Schema schema = schemaFactory.newSchema(schemas.toArray(new Source[schemas.size()]));
                   Validator validator = schema.newValidator();
                   validator.setErrorHandler(new ErrorHandler() {
                        @Override
                        public void error(SAXParseException e) throws SAXException {
                             errorMessage.setErrorMessage(e.getMessage());
                             errorMessage.setLineNumber(e.getLineNumber());
                             errorMessage.setColumnNumber(e.getLineNumber());
                             throw e;
                        @Override
                        public void fatalError(SAXParseException e) throws SAXException {
                             errorMessage.setErrorMessage(e.getMessage());
                             errorMessage.setLineNumber(e.getLineNumber());
                             errorMessage.setColumnNumber(e.getLineNumber());
                             throw e;
                        @Override
                        public void warning(SAXParseException e) throws SAXException {
                             errorMessage.setErrorMessage(e.getMessage());
                             errorMessage.setLineNumber(e.getLineNumber());
                             errorMessage.setColumnNumber(e.getLineNumber());
                             throw e;
                   StreamSource source = new StreamSource(new File(filePath));
                   validator.validate(source);
              } catch (SAXParseException e) {
                   return false;
              } catch (SAXException e) {
                   errorMessage.setErrorMessage(e.getMessage());
                   return false;
              } catch (FactoryConfigurationError e) {
                   errorMessage.setErrorMessage(e.getMessage());
                   return false;
              } catch (IOException e) {
                   errorMessage.setErrorMessage(e.getMessage());
                   return false;
              return true;
         public ErrorMessage getErrorMessage() {
              return errorMessage;
    }Edited by: erossy on Aug 31, 2010 1:56 AM

  • Validating XML against XSD

    Hi,
    I would like to validate XML against XSD using SAX parser. Can any one help, where I can get information. I could get some information of XML validation against DTD. But could not get much information for XSD validation.
    Which parser is good for validation against XSD? or shall I continue with SAX Parser?
    Kumaravel

    I use the "Summer 02 XML Pack" provided here at Sun, which is based on Xerces2 by Apache (http://xml.apache.org/xerces2-j/index.html). Actually with that, validation against schemas is pretty much like validation against DTDs, as long as the schema is referenced in your XML file and you switch on schema validation in the parser like
    reader.setFeature("http://xml.org/sax/features/validation", true);
    reader.setFeature("http://apache.org/xml/features/validation/schema", true);Xerces2 works both with DOM and SAX (I use SAX). You should browse Apache's website a bit. There's not too much information, but I guess it's enough to get started.

  • Validate XML against XSD with imported xsd's

    Hello,
    I'm stuck for a while attempting to validate a xml against some xsd's. In the code below you can find my xsd's structure: (I need to use this structure in order to reuse the baseXsd's files.
    CommonTypes.xsd
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="CommonTypes" targetNamespace="http://test.com/CommonTypes"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    attributeFormDefault="qualified">
    <xs:simpleType name="NonEmptyString">
    <xs:restriction base="xs:string">
    <xs:minLength value="1"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:schema>
    CommonLog.xsd
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="CommonLogConfig"
    targetNamespace="http://test.com/CommonLogConfig"
    xmlns:cmn="http://test.com/CommonTypes"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    attributeFormDefault="qualified">
    <xs:import schemaLocation="..\Base\CommonTypes.xsd" namespace="http://test.com/CommonTypes" />
    <xs:simpleType name="LogName">
    <xs:restriction base="xs:string"/>
    </xs:simpleType>
    <xs:simpleType name="LogPath">
    <xs:restriction base="cmn:NonEmptyString"/>
    </xs:simpleType>
    </xs:schema>
    LogConfig.xsd
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:mlc="http://test.com/CommonLogConfig"
    targetNamespace="component1_LogConfig"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    attributeFormDefault="qualified">
    <xs:import schemaLocation="..\Base\CommonLogConfig.xsd" namespace="http://test.com/CommonLogConfig" />
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="default">
    <xs:complexType>
    <xs:all>
    <xs:element name="LogName" type="mlc:LogName" fixed="component.name" />
    <xs:element name="LogPath" type="mlc:LogPath"/>
    </xs:all>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    LogConfig.xml
    <?xml version="1.0" encoding="utf-8"?>
    <root xmlns="component1_LogConfig">
    <default>
    <LogName>component.name</LogName>
    <LogPath></LogPath>
    </default>
    </root>
    As you can probably notice, the <LogPath> key on the LogConfig is empty, but, it is defined as a NonEmptyString type. That is the way I'm validating the xml against xsd:
    FileStream stream = new FileStream("LogConfig.xml", FileMode.Open);
    XmlValidatingReader vr = new XmlValidatingReader(stream, XmlNodeType.Element, null);
    vr.Schemas.Add(null, "LogConfig.xsd");
    vr.ValidationType = ValidationType.Schema;
    vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
    while (vr.Read()) ;
    The validationCallBack is not being fired.
    I suppose it is possible since the visual studio show me the error at compile time:

    Well, it is weird, but, the code below works when validating the NonEmptyString type:
    XmlSchemaSet schemaSet = new XmlSchemaSet();
    schemaSet.Add(null, "LogConfig.xsd");
    XDocument doc1 = XDocument.Load("LogConfig.xml");
    doc1.Validate(schemaSet, new ValidationEventHandler(ValidationCallBack), false);
    However, if I leave the <LogName> empty it does not valid the values set on xsd fixed attribute, 
    The solution?
    Well, I'm validating the same xml twice, the code above and the code on my first question.

  • How to validate XML against XSD and parse/save in one step using SAXParser?

    How to validate XML against XSD and parse/save in one step using SAXParser?
    I currently have an XML file and XSD. The XML file specifies the location of the XSD. In Java code I create a SAXParser with parameters indicating that it needs to validate the XML. However, SAXParser.parse does not validate the XML, but it does call my handler functions which save the elements/attributes in memory as it is read. On the other hand, XMLReader.parse does validate the XML against the XSD, but does not save the document in memory.
    My code can call XMLReader.parse to validate the XML followed by SAXParser.parse to save the XML document in memory. But this sound inefficient. Besides, while a valid document is being parsed by XMLReader, it can be changed to be invalid and saved, and XMLReader.parse would be looking at the original file and would think that the file is OK, and then SAXParser.parse would parse the document without errors.
    <Book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="book.xsd" name="MyBook">
      <Chapter name="First Chapter"/>
      <Chapter name="Second Chapter">
        <Section number="1"/>
        <Section number="2"/>
      </Chapter>
    </Book>
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Book">
    <xs:complexType>
      <xs:sequence>
       <xs:element name="Chapter" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
         <xs:sequence>
          <xs:element name="Section" minOccurs="0" maxOccurs="unbounded">
           <xs:complexType>
            <xs:attribute name="xnumber"/>
          </xs:complexType>
          </xs:element>
         </xs:sequence>
         <xs:attribute name="name"/>
        </xs:complexType>
       </xs:element>
      </xs:sequence>
      <xs:attribute name="name"/>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    public class SAXXMLParserTest
       public static void main(String[] args)
          try
             SAXParserFactory factory = SAXParserFactory.newInstance();
             factory.setNamespaceAware(true);
             factory.setValidating(true);
             SAXParser parser = factory.newSAXParser();
             parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                                "http://www.w3.org/2001/XMLSchema");
             BookHandler handler = new BookHandler();
             XMLReader reader = parser.getXMLReader();
             reader.setErrorHandler(handler);
             parser.parse("xmltest.dat", handler); // does not throw validation error
             Book book = handler.getBook();
             System.out.println(book);
             reader.parse("xmltest.dat"); // throws validation error because of 'xnumber' in the XSD
    public class Book extends Element
       private String name;
       private List<Chapter> chapters = new ArrayList<Chapter>();
       public Book(String name)
          this.name = name;
       public void addChapter(Chapter chapter)
          chapters.add(chapter);
       public String toString()
          StringBuilder builder = new StringBuilder();
          builder.append("<Book name=\"").append(name).append("\">\n");
          for (Chapter chapter: chapters)
             builder.append(chapter.toString());
          builder.append("</Book>\n");
          return builder.toString();
       public static class BookHandler extends DefaultHandler
          private Stack<Element> root = null;
          private Book book = null;
          public void startDocument()
             root = new Stack<Element>();
          public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
             if (qName.equals("Book"))
                String name = attributes.getValue("name");
                root.push(new Book(name));
             else if (qName.equals("Chapter"))
                String name = attributes.getValue("name");
                Chapter child = new Chapter(name);
                ((Book)root.peek()).addChapter(child);
                root.push(child);
             else if (qName.equals("Section"))
                Integer number = Integer.parseInt(attributes.getValue("number"));
                Section child = new Section(number);
                ((Chapter)root.peek()).addSection(child);
                root.push(child);
          public void endElement(String uri, String localName, String qName) throws SAXException
             Element finished = root.pop();
             if (root.size() == 0)
                book = (Book) finished;
          public Book getBook()
             return book;
          public void error(SAXParseException e)
             System.out.println(e.getMessage());
          public void fatalError(SAXParseException e)
             error(e);
          public void warning(SAXParseException e)
             error(e);
    public class Chapter extends Element
       public static class Section extends Element
          private Integer number;
          public Section(Integer number)
             this.number = number;
          public String toString()
             StringBuilder builder = new StringBuilder();
             builder.append("<Section number=\"").append(number).append("\"/>\n");
             return builder.toString();
       private String name;
       private List<Section> sections = null;
       public Chapter(String name)
          this.name = name;
       public void addSection(Section section)
          if (sections == null)
             sections = new ArrayList<Section>();
          sections.add(section);
       public String toString()
          StringBuilder builder = new StringBuilder();
          builder.append("<Chapter name=\"").append(name).append("\">\n");
          if (sections != null)
             for (Section section: sections)
                builder.append(section.toString());
          builder.append("</Chapter>\n");
          return builder.toString();
    }Edited by: sn72 on Oct 28, 2008 1:16 PM

    Have you looked at the XML DB FAQ thread (second post) in this forum? It has some examples for validating XML against schemas.

  • Getting an Out of memory exception while validating XML against XSD

    Hello friends,
    I am getting an Out Of Memory exception while validating my XML against a given XSd which is huge.
    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
            saxParserFactory.setValidating(true);
              SAXParser saxParser = saxParserFactory.newSAXParser();
             saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
             saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",new File("C:/todelxsd.xsd")); as u may see the darkened code. this basically Loads the XSD in Memmory , and JVM throws an out of Memory exception. is there any other way round of validating an XML against an XSD where i dont have to load my XSD if not then kindly let me know the solution for above problem .
    Thanks.

    Yes, but increasing the heap size is a temporary solution , isnt there a way where the XML can be validated against an XSD without having to load XSD in memory

  • Validate XML against XSD

    Hi. I need to validate an XML file against XSD schema.
    How can I do it with PL/SQL?
    Thanks a lot
    Alejandro

    Well, it is weird, but, the code below works when validating the NonEmptyString type:
    XmlSchemaSet schemaSet = new XmlSchemaSet();
    schemaSet.Add(null, "LogConfig.xsd");
    XDocument doc1 = XDocument.Load("LogConfig.xml");
    doc1.Validate(schemaSet, new ValidationEventHandler(ValidationCallBack), false);
    However, if I leave the <LogName> empty it does not valid the values set on xsd fixed attribute, 
    The solution?
    Well, I'm validating the same xml twice, the code above and the code on my first question.

  • How to Validate XML against XSD through PL/SQL?

    Hi friends,
    I m new to this forum. This is my first query.
    In our project, we are trying to generate output XML using PL/SQL procedure. I have done that successfully. Now my problem is I have to validate this against our XSD. How will I do that? Can you provide me with a sample example.
    Thanks to all in advance.
    Regards,
    apk

    Have you looked at the XML DB FAQ thread (second post) in this forum? It has some examples for validating XML against schemas.

  • HOW TO USE isSchemaValid() in oracle 9i to validate XML against XSD

    Hi
    I am trying to validate xml file against xsd in oracle 9i.The steps are as follows:
    *1.Created directory for xml and xsd file location:*
    CREATE or replace DIRECTORY XML_DATA AS 'D:\prod\sample xml and xsd;
    *2.Register the schema*
    DECLARE
    bf5 BFILE;
    BEGIN
    -- Register the schema
    dbms_lob.filecloseall;
    bf5 := BFILENAME('XML_DATA','xml1.xsd');
    DBMS_XMLSCHEMA.registerSchema('http://www.example.com/schemas/ipo.xsd',bf5,TRUE, TRUE, FALSE,TRUE,TRUE);
    -- dbms_lob.fileclose(bf5);
    END;
    *3.creatibg table to store xml files*
    CREATE TABLE po_tab2 (id NUMBER,xmlcol SYS.XMLType) ;
    *4.Inserting xml file into the table and validating that file with xml schema*
    declare
    aa clob:=' ';
    b varchar2(4000);
    c xmltype;
    begin
    dbms_lob.filecloseall;
    aa:= GETCLOBDOCUMENT('XML_DATA','example.XML','WE8MSWIN1252');
    INSERT INTO po_tab2 (ID, XMLCOL)
    VALUES
    (104,sys.XMLType.createXML(aa));
    commit;
    --c:=sys.xmltype.createXml(aa);
    c:=xmltype(aa);
    b:=VerifyXML(c,'http://www.example.com/schemas/ipo.xsd');
    dbms_output.put_line(b);
    end;
    _5.VerifyXML function is:_
    create or replace
    function VerifyXML( xml xmltype, xmlSchema varchar2 ) return varchar2 AUTHID DEFINER is
    xmlURL varchar2(4000);
    begin
    select
    s.qual_schema_url into xmlURL
    from user_xml_schemas s
    where s.schema_url = xmlSchema;
    if xml.isSchemaValid(xmlURL,'ManageRolloutRegionNotification') =1 then
    return( 'Valid. The supplied XML complies with XSD '||xmlURL );
    else
    -- return null;
    return(sqlcode|| 'Failed. The supplied XML does not comply with XSD '||xmlURL );
    end if;
    exception when others then
    return(sqlcode);
    end;
    _6.PROBLEM:_
    the problem is the function is always returning 'Failed ' status even though I am giving the correct file.. Is there any method to find the reason for failure. These codes are working fine oracle 11g. currently i am working in 9i version 9.2.0.1.0. I

    Oracle 9iR2 is not supported anymore.
    Oracle 9.2.0.8 is in sustained support.
    Oracle 9.2.0.1 is not supported at all.
    Upgrade to 11gR2.
    Sybrand Bakker
    Senior Oracle DBA

  • Validate XML against XSD using PLSQL

    Hi,
    We now need some kind of automated solution that will pick
    up the XMLs from a specific location or table and validate them
    against the XSD in only Oracle PLSQL.
    The validation of the XML against the XSD should take place when the XML is parsed.
    I want to know how first the XSD's are stored or registered in the Oracle XDB repository.
    Please can anyone suggest me how this can be done with a simple example
    with a sample XML and XSD?
    Regards,
    Marlon.

    Hi, I'm not an expert but I've been reading a lot and I found this and it works. I'll hope it is useful.(Oracle 10)
    declare
    -- Local variables here
    res BOOLEAN;
    tempXML XMLType;
    xmlDoc XMLType;
    xmlSchema XMLType;
    schemaURL varchar2(256) := 'testcase.xsd';
    schemaPath varchar2(256) := '/public/testcase.xsd';
    begin
    dbms_xmlSchema.deleteSchema(schemaURL,4);
    -- Test statements here
    xmlSchema := xmlType(
    '<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="root" xdb:defaultTable="ROOT_TABLE">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="child1"/>
    <xs:element name="child2"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    dbms_xmlschema.registerSchema(schemaURL,
    xmlSchema , --xdbURIType(schemaPath).getClob(),
    TRUE,TRUE,FALSE,TRUE
    xmlDoc:=xmltype('<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="' || schemaURL || '"><child1>foo</child1><child2>bar</child2></root>');
    dbms_output.put_line(xmlDoc.getStringVal());
    xmlDoc.schemaValidate();
    END;

  • Parse XML against XSD

    Does anyone know if it's possible to parse an XML document
    against an XSD file using Flex/AS3?

    Does anyone know if it's possible to parse an XML document
    against an XSD file using Flex/AS3?

  • When validating XML against XSD DateTime not getting recognised

    In the XSD the element is defined as
    <xs:element name="CreateDate" type="xs:dateTime" nillable="true" minOccurs="0"/>
    <xs:element name="CreateUser" type="xs:string" nillable="true" minOccurs="0"/>
    <xs:element name="ModifyDate" type="xs:dateTime" nillable="true" minOccurs="0"/>
    in the XML
    <CreateDate>1995-04-19 14:37:43</CreateDate>
    <CreateUser>JDC</CreateUser>
    <ModifyDate>2010-09-21 14:37:43</ModifyDate>
    When i validate it
    its throwing me error.
    ORA-30992 error occured at xpath
    ORA-01861 leteral does not match format string.
    But when i remove the Time part then it is not throwing error.
    <CreateDate>1995-04-19</CreateDate>
    <CreateUser>JDC</CreateUser>
    <ModifyDate>2010-09-21</ModifyDate>
    Help me out.

    Your date/time value is formatted incorrectly.
    See http://www.w3.org/TR/xmlschema-2/#dateTime
    The ·lexical space· of dateTime consists of finite-length sequences of characters of the form: '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?, whereSo you are missing the T between the date and time.
    I will agree that the error message is not too helpful. How are you validating it and what version of Oracle (4 digits)?

  • Using XSL on XML validated against XSD

    Transforming XSD validated XMLType Data
    Re: example XSL in Chapter 6 that transforms XML with associated XSD schema definition (Oracle 9i XML Database Developer's Guide)
    I noted that this XSL uses only the "general" node identification functions (e.g., name() ) to access nodes in the <xsl:value-of select..>. I have also noted that standard XSL templates from other sections of the documentation, for example in Chapter 3 and in Appendix D, do not work with an XML which is validated against an XSD schema.
    Can anyone give me an example <xsl:value-of select..> that addresses a specific node in the "purchase order" example, like the shipTo, name, street -- or any other specific node. This is critical since there is always bound to be node-specific processing in any transformation, and this is not demonstrated by any example of XML which has been validated against an XSD.
    I have tried this endlessly on my own examples of XML w/XSD validation. Even if the value-of select="name(.)" tells you that the name of the node is "FooBar", you cannot use FooBar as a select test to do FooBar specific processing.
    Help?????

    Not quite understand your question. Can you send me the example doc?

  • How can I validate the ejb-jar.xml against a downloaded ejb-jar_2_1.xsd

    I downloaded all configuration XML file schema,
    so we can point to the schema locally. (To be able to work
    even the network is not there.)
    I tried to change the xmlns, xmlns:xsi and xsi:schemaLocation in the root element of ejb-jar.xml file,
    I can't figure out how to make the server load the local ejb-jar_2_1.xsd file.
    I'll appreciate someone can explain how the xsd file is loaded.
    Thanks
    Zhong

    or use a tool like XMLSpy to validate your ejb-jar.xml against the XSD.
    Cheers!
    Dips

  • Getting an out of memory exception while validating my XML against a XSD

    Hello friends,
    I have asked this question in following thread too. Pasting it again here just to saye your time
    http://forum.java.sun.com/thread.jspa?threadID=690812&tstart=0
    I am getting an Out Of Memory exception while validating my XML against a given XSd which is huge.
    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
            saxParserFactory.setValidating(true);
              SAXParser saxParser = saxParserFactory.newSAXParser();
             saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
             saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",new File("C:/todelxsd.xsd")); as u may see the darkened code. this basically Loads the XSD in Memmory , and JVM throws an out of Memory exception. is there any other way round of validating an XML against an XSD where i dont have to load my XSD if not then kindly let me know the solution for above problem .
    Thanks.

    Yes, but increasing the heap size is a temporary solution , isnt there a way where the XML can be validated against an XSD without having to load XSD in memory

Maybe you are looking for