Validate XML Schema

Hi,
I need to load some XML schema definitions to afterwards validate some DOM documents against this schemas. My problem is, when loading those XML schema definitions I have to validate them. How to do this? How to provide an javax.xml.validation.Schema object and check is valid XML schema?
Thanks in advance.

The very act of loading the schema into a schema object will validate it. That is, if you get as far as having an instance of Schema, it's valid.

Similar Messages

  • Switching ON validate xml(Schema Validation) in BPEL Console for AIAtesting

    While we were testing Oracle O2B pip, we have recently switched on schema validation by turning it on to 'Strict' so that we can Validate
    XML in BPEL Console. Earlier when we were testing we had turned the schema validation as 'None' on BPEL console, and hence everything was working fine and
    no errors we popping out while creating sales order in Siebel CRM. But the moment we put validate xml to ' Strict' it starts throwing validation errors.
    So can you please help us to know whether it is right to test the Oracle O2B pip by putting validate xml to 'Strict'? If it is fair to test it by switching
    ON Validate XML(putting validate xml to 'Strict') then we are getting below error.
    We are creating a new sales order in Siebel CRM and when we check in BPEL console it was faulted at UpdateSalesOrderSiebelCommsProvABCSImpl (v. 1.0) .When we checked the BPEL flow it is throwing error at InvokeUpdateUpsert.
    Error is According to the xml schemas, the xml document is invalid. The reason is: Error::cvc-complex-type.2.4.a: Invalid content was found starting with element 'xsdLocal1:Process_spcInstance_spcId'. One of '{"http://siebel.com/asi":Process_spcInstance_spcId}' is expected.
    Steps for Switching on Validation ?
    1)     Login to BPEL Console
    2)     Go To Configuration section
    3)     Schema Validation changes
    a.     ON: populate validateXML with value strict
    b.     OFF: populate validateXML with value none
    Really appreciate if you can help..

    hi
    Indeed, the "Validate XML" menu option only shows "Validate XML: 0 errors, 0 warnings.".
    But, if you look at the "Design" tab for your schema, the "invoices" element node contains an "xsd:invoice" sequence shown in red. If you change "xsd:invoice" to "invoice" this becomes white and the node can be expanded.
    One other thing, registering an XML Schema in JDeveloper like the one you posted, isn't possible without an "oracle.xml.parser.schema.XSDException" (without further details).
    regards
    Jan Vervecken

  • How to validate XML Schema in DOM?

    I've got an XML file and corresponding XSD file.
    How do I validate this XML file when using DOM parser?
    Thanks

    You can use the sun msv API.
    This multi schema validator can validate documents against different sorts of Schema.
    More info at http://wwws.sun.com/software/xml/developers/multischema/

  • XML Schema Collection (SQL Server 2012): How to create an XML Schema Collection that can be used to Validate a field name (column title) of an existing dbo Table of a Database in SSMS2012?

    Hi all,
    I used the following code to create a new Database (ScottChangDB) and a new Table (marvel) in my SQL Server 2012 Management Studio (SSMS2012) successfully:
    -- ScottChangDB.sql saved in C://Documents/SQL Server XQuery_MacLochlainns Weblog_code
    -- 14 April 2015 09:15 AM
    USE master
    IF EXISTS
    (SELECT 1
    FROM sys.databases
    WHERE name = 'ScottChangDB')
    DROP DATABASE ScottChangDB
    GO
    CREATE DATABASE ScottChangDB
    GO
    USE ScottChangDB
    CREATE TABLE [dbo].[marvel] (
    [avenger_name] [char] (30) NULL, [ID] INT NULL)
    INSERT INTO marvel
    (avenger_name,ID)
    VALUES
    ('Hulk', 1),
    ('Iron Man', 2),
    ('Black Widow', 3),
    ('Thor', 4),
    ('Captain America', 5),
    ('Hawkeye', 6),
    ('Winter Soldier', 7),
    ('Iron Patriot', 8);
    SELECT avenger_name FROM marvel ORDER BY ID For XML PATH('')
    DECLARE @x XML
    SELECT @x=(SELECT avenger_name FROM marvel ORDER BY ID FOR XML PATH('Marvel'))--,ROOT('root'))
    SELECT
    person.value('Marvel[4]', 'varchar(100)') AS NAME
    FROM @x.nodes('.') AS Tbl(person)
    ORDER BY NAME DESC
    --Or if you want the completed element
    SELECT @x.query('/Marvel[4]/avenger_name')
    DROP TABLE [marvel]
    Now I am trying to create my first XML Schema Collection to do the Validation on the Field Name (Column Title) of the "marvel" Table. I have studied Chapter 4 XML SCHEMA COLLECTIONS of the book "Pro SQL Server 2008 XML" written by
    Michael Coles (published by Apress) and some beginning pages of XQuery Language Reference, SQL Server 2012 Books ONline (published by Microsoft). I mimicked  Coles' Listing 04-05 and I wanted to execute the following first-drafted sql in
    my SSMS2012:
    -- Reference [Scott Chang modified Listing04-05.sql of Pro SQL Server 2008 XML by Michael Coles (Apress)]
    -- [shcColes04-05.sql saved in C:\\Documents\XML_SQL_Server2008_code_Coles_Apress]
    -- [executed: 2 April 2015 15:04 PM]
    -- shcXMLschemaTableValidate1.sql in ScottChangDB of SQL Server 2012 Management Studio (SSMS2012)
    -- saved in C:\Documents\XQuery-SQLServer2012
    tried to run: 15 April 2015 ??? AM
    USE ScottChangDB;
    GO
    CREATE XML SCHEMA COLLECTION dbo. ComplexTestSchemaCollection_all
    AS
    N'<?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="marvel">
    <xsd:complexType>
    <xsd:all>
    <xsd:element name="avenger_name" />
    <xsd:element name="ID" />
    </xsd:all>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>';
    GO
    DECLARE @x XML (dbo. ComplexTestSchemaCollection_all);
    SET @x = N'<?xml version="1.0"?>
    <marvel>
    <avenger_name>Thor</name>
    <ID>4</ID>
    </marvel>';
    SELECT @x;
    GO
    DROP XML SCHEMA COLLECTION dbo.ComplexTestSchemaCollection_all;
    GO
    I feel that drafted sql is very shaky and it needs the SQL Server XML experts to modify to make it work for me. Please kindly help, exam the coding of my shcXMLTableValidate1.sql and modify it to work.
    Thanks in advance,
    Scott Chang

    Hi Scott,
    2) Yes, FOR XML PATH clause converts relational data to XML format with a specific structure for the "marvel" Table. Regarding validate all the avenger_names, please see below
    sample.
    DECLARE @x XML
    SELECT @x=(SELECT ID ,avenger_name FROM marvel FOR XML PATH('Marvel'))
    SELECT @x
    SELECT
    n.value('avenger_name[1]','VARCHAR(99)') avenger_name,
    n.value('ID[1]','INT') ID
    FROM @x.nodes('//Marvel') Tab(n)
    WHERE n.value('ID[1]','INT') = 1 -- specify the ID here
    --FOR XML PATH('Marvel')  --uncommented this line if you want the result as element type
    3)i.check the xml schema content
    --find xml schema collection
    SELECT ss.name,xsc.name collection_name FROM sys.xml_schema_collections xsc JOIN sys.schemas ss ON xsc.schema_id= ss.schema_id
    select * from sys.schemas
    --check the schema content,use the name,collection_name from the above query
    SELECT xml_schema_namespace(N'name',N'collection_name')
    3)ii. View can be viewed as virtual table. Use a view to list the XML schema content.
    CREATE VIEW XSDContentView
    AS
    SELECT ss.name,xsc.name collection_name,cat.content
    FROM sys.xml_schema_collections xsc JOIN sys.schemas ss ON xsc.schema_id= ss.schema_id
    CROSS APPLY(
    SELECT xml_schema_namespace(ss.name,xsc.name) AS content
    ) AS cat
    WHERE xsc.name<>'sys'
    GO
    SELECT * FROM XSDContentView
    By the way, it would be appreciated if you can spread your questions into posts. For any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • How to validate generated XML-Document in Memory by XML-Schema?

    Hi all!
    I have the following problem:
    I am generating a Document using the DOM delivered with Xerces 2.6.2.
    Before I'll send the generated xml-document through network to another system I have to check with my xml-schema if the document is correct.
    In the DOM-FAQ I found an "example" trying to explain how it should work. But with this example the problems begin.
    I am creating my document with this method:
         public void createDocument() {
              myDOM = DOMImplementationImpl.getDOMImplementation();
              doc = myDOM.createDocument("", "documentData", null);
              root = doc.getDocumentElement();
              root.setAttribute(
                   "xmlns:xsi",
                   "http://www.w3.org/2001/XMLSchema-instance");
              //          root.setAttribute("xsi:noNamespaceSchemaLocation", "myScheme.xsd");
              domConfig = ((DocumentImpl) doc).getDomConfig();
              domConfig.setParameter(
                   "schema-location",
                   "file:///d:/workspace/XMLProject/WebContent/WEB-INF/myScheme.xsd");
              domConfig.setParameter("error-handler", new EHandler());
              domConfig.setParameter("validate", Boolean.TRUE);
         }In the line getting the domConfig, it is getting differeing to the example: The example is like this:
    import org.w3c.dom.Document;
    import org.w3c.dom.DOMConfiguration;
    import org.w3c.dom.ls.LSParser;
    Document document = builder.parseURI("data/personal-schema.xml");
    DOMConfiguration config = document.getConfig();
    config.setParameter("error-handler",new MyErrorHandler());
    config.setParameter("validate", Boolean.TRUE);
    document.normalizeDocument();They get the DOM-Configuration from the document-Object, but my document-Object has no "getConfig()" and only after type-casting I get a getDomConfig()-Method to get the configuration.
    Then I fill my document and call                
    ((DocumentImpl) doc).normalizeDocument();When I run my Application I get the following error:
    org.w3c.dom.DOMException: FEATURE_NOT_SUPPORTED: The parameter schema-location is recognized but the requested value cannot be set.
         at org.apache.xerces.dom.DOMConfigurationImpl.setParameter(Unknown Source)
         at xmlProject.createDocument(Convert.java:63)
         at xmlProject.Convert.main(Convert.java:154)I tried several ways to get the validation without success.
    The next question is how I should refer to my xml-schema (which path) and where to place it relative to my jar I will generate, because I will have no webserver I could place it on.
    Has anyone any experience with validating a document created and not placed on disc?
    I have also another question to SAX: I read, that it is reading a document without saving it in the memory. I think this means that if I am validating it by SAX it will be read once and for parsing it will be read a second time. If I would transfer the document over an tcp-connection, I only have the document once in my inputstream and after validation it would be consumed I think. But what can I parse then? Or did I missed a detail with the function of the SAX?
    Thank you for your help!
    Yours
    Christian

    static final String schemaSource = argv[0];
    static final String JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    factory.setAttribute(JAXP_SCHEMA_SOURCE,
    new File(schemaSource));

  • How to validate xml file with XSD schema ??  in JDK1.4.2

    How to validate xml file with XSD schema ?? in JDK1.4.2
    i dont want to use new Xerec Jar ...
    Suggest option ...

    Please do not double-post. http://forum.java.sun.com/thread.jspa?threadID=5134447&tstart=0
    Then use Stax (Woodstock) or Saxon.
    - Saish

  • Validate XML with Schema?

    So, according to Adobe...
    quote:
    Dreamweaver CS3 continues to support not only the creation
    and editing of XML and XSL files, but it also allows you to import
    DTDs and schemas and to validate XML documents.
    Does anyone know how to accomplish this task? Adobe's
    documentation on this topic seems be less current than their
    marketing material.
    I mean, I'm assuming from the way this is worded it means
    that you can "import DTDs and schemas and ... validate XML
    documents"
    with said schemas. Or is this just some shifty marketing
    trickery which really means you can import (i.e., open) a DTD or
    schema, and, as a completely unrelated task, you can "validate"
    your XML file - to the extent that Dreamweaver will tell you if you
    forgot to close a tag?

    I tried to move all the xml, class and xsd files in the same folder and it still didn't work...
    And I can't hard coded the xsd file on the document... so the only way is to set the xsd location inside the java codes... here's what I have:
    static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
    static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
    File xsdFile = new File("schema.xsd");
    saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    saxParser.setProperty(JAXP_SCHEMA_SOURCE, xsdFile);
    Please help... thx.

  • How do you validate XML file against a Schema?

    Are there free applications that does that?

    Thanks, but how do you validata the Schema itself, which is an XML file.
    I know the schema DTD is online, but still I need some utility to do it
    Thanks

  • Validate xml with complextype schema without root element!

    Hi All!
    I have a problem that. I want to validate a xml data of complextype but the schema i want to validate is[b] not have root element.
    For example:
    The schema like that
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="www.thachpn.test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="www.thachpn.test" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:complexType name="Name">
              <xs:sequence>
                   <xs:element name="FirstName" type="xs:string"/>
                   <xs:element name="LastName" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>
    and the xml data i want to validate like this
    <?xml version="1.0" encoding="UTF-8"?>
    <Name xmlns="www.thachpn.test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <FirstName>Pham</FirstName>
         <LastName>Thach</LastName>
    </Name>
    My Algorithm is like that:
    I create a complextype object by above schema
    then i create new element with given name and namespace
    after that i use schema of this element to validate xml data.
    I use xmlparserv2 lib of oracle
    But i can not find how to create complextype from schema or create element with have complextype.
    Please help me.
    Thanks a lot!

    <?xml version="1.0" encoding="UTF-8"?>
    Modify the schema.
    Add a root element.
    <xs:schema targetNamespace="www.thachpn.test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="www.thachpn.test" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:element name="Name" type="Name"/>
    <xs:complexType name="Name">
    <xs:sequence>
    <xs:element name="FirstName" type="xs:string"/>
    <xs:element name="LastName" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>

  • Which tech is for validate xml to specific xml schema at runtime

    I got a request.
    we have input xml, we have the xml schema.
    we need to validate xml and see if it follows the schema at run time.
    which tech is good and pupolar for this request in the market
    Thanks.
    Jack Tie

    JDK 1.5:
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute(
                "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                XMLConstants.W3C_XML_SCHEMA_NS_URI);
        factory.setAttribute(
                "http://java.sun.com/xml/jaxp/properties/schemaSource",
                urlAsString);
        DocumentBuilder builder = newDocumentBuilder(factory);
        builder.setErrorHandler(errorHandler);
        builder.parse();

  • Can not validate XML against schema

    Hi all,
    I'm new to XML validation. I have this sample from net.
    this is the schema definition:
    <xs:schema targetNamespace="http://www.w3schools.com" elementFormDefault="qualified">
    <xs:element name="note" type="xs:string"/>
    </xs:schema>
    and this is the xml file:
    <?xml version="1.0"?>
    <note xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com note.xsd">
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>
    when i try to validate at http://schneegans.de/sv/, this is a validator i found searching
    it gives error
    The root element does not comply with the schema. (2:2)
    any ideas?
    i have created my own xml and schema.I registered the xsd on oracle 10g but i get the same error :(
    where can i validate my xml against a schema?
    thanx a lot

    Validating XML Documents Against XML Schema
    http://www.oracle.com/technology/pub/articles/vohra_xmlschema.html

  • Validate XML against Xml Schema using JDBC (thin_driver)

    hi all,
    i have a table with a xmltype-column (XmlSchema Support) and i wonna load(and validate) xml-data( as String) in the xmltype-column.
    some thing like this :
    int count=1;
    String SQLTEXT=null;
    Statement stmt=null;
    ResultSet rs =null;
    //while(count<=1000)
    try
    stmt = connection.createStatement();
    rs = stmt.executeQuery("select SEQ_patxmlschema_ID.NEXTVAL from patxmlschema");
    if(rs.next())
    id =rs.getLong(1);
    System.out.println(id);
    stmt.close();
    stmt=null;
    rs.close();
    SQLTEXT = "INSERT INTO patxmlschema(id, patID, name, status, patInfo)"+
              "VALUES(?,?,?,?,XMLType(?))";
    pStmt = connection.prepareStatement(SQLTEXT);
    long patID = random.nextInt(30000);
    System.out.println("patId: "+ patID);
    String name = RandomStringUtils.random(6,true,false);
    System.out.println("lastname: "+ name);
    String firstname=RandomStringUtils.random(5,true,false);
    System.out.println("firstname: "+ firstname);
    String status=RandomStringUtils.random(8,true,false);
    System.out.println("status: "+ status);
    String street=RandomStringUtils.random(6,true,false);
    System.out.println("street: "+ street);
    String zip=RandomStringUtils.random(5,false,true);
    System.out.println("zip: "+ zip);
    String city=RandomStringUtils.random(6,true,false);
    System.out.println("city: "+ city);
    String phone=RandomStringUtils.random(8,false,true);
    String email=RandomStringUtils.random(15,true,false);
    String state=RandomStringUtils.random(6,true,false);
    String country=RandomStringUtils.random(6,true,false);
    System.out.println("country: "+ country);
    xmldoc=
         "<Patient>"+                    "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+          "xsi:noNamespaceSchemaLocation='http://olidong.net/patInfo.xsd'>"+
         "<Address>"+                         "<street>"+street+"</street>"+                         "<city>"+city+"</city>"+                    "<zip>"+zip+"</zip>"+
         "<state>"+state+"</state>"+                    "<country>"+country+"</country>"+
         "</Address>"+               "<phone>"+phone+"</phone>"+                    "<email>"+email+"</email>"+
         "</Patient>";
         pStmt.setLong(1, id);
         pStmt.setLong(2, patID);
         pStmt.setString(3, name);
         pStmt.setString(4, status);
         pStmt.setString(5, xmldoc);
         pStmt.executeUpdate();
    pStmt.close();
         pStmt=null;
         count++;
         //connection=null;
    catch(Exception e){
    e.printStackTrace();
    can you help me?
    Olidong

    hi Avi,
    my xml doc is valid. with the sqlplus the are no problem or error. tryng the same with jddbc(thin driver) i got this error.
    i don´t know, may be jdbc don´t support xml schema support insertion.
    i got this sample:
    DECLARE
    doc VARCHAR2(2000) :=
    '<schema
    targetNamespace="http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
    xmlns:po="http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
    xmlns="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">
    <complexType name="PurchaseOrderType">
    <sequence>
    <element name="PONum" type="decimal"/>
    <element name="Company">
    <simpleType>
    <restriction base="string">
    <maxLength value="100"/>
    </restriction>
    </simpleType>
    </element>
    <element name="Item" maxOccurs="1000">
    <complexType>
    <sequence>
    <element name="Part">
    <simpleType>
    <restriction base="string">
    <maxLength value="20"/>
    </restriction>
    </simpleType>
    </element>
    <element name="Price" type="float"/>
    </sequence>
    </complexType>
    </element>
    </sequence>
    </complexType>
    <element name="PurchaseOrder" type="po:PurchaseOrderType"/>
    </schema>';
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    'http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd', doc);
    END;
    CREATE TABLE mypurchaseorders OF XMLType
    XMLSchema "http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
    ELEMENT "PurchaseOrder"
    VARRAY xmldata."Item" STORE AS TABLE item_nested;
    INSERT INTO mypurchaseorders
    VALUES(
    XMLType(
    '<PurchaseOrder
    xmlns="http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
    = "http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd
    http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd">
    <PONum>1001</PONum>
    <Company>IBM</Company>
    <Item>
    <Part>DB2 v9 Set</Part>
    <Price>2550</Price>
    </Item>
    <Item>
    <Part>8i Doc Set</Part>
    <Price>350</Price>
    </Item>
    </PurchaseOrder>'));
    with the sqlplus the are no error
    but insert with java jdbc:
    SQLTEXT = "INSERT INTO mypurchaseorders VALUES(XMLType(?))";
    String xmldoc= "<PurchaseOrder"+
    "xmlns='http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd'" +
    "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    "xsi:schemaLocation= 'http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd'"+
    "'http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd'>"+
    "<PONum>1001</PONum>"+
    "<Company>IBM</Company>"+
    "<Item> "+
    "<Part>DB2 v9 Set</Part>"+
    "<Price>2550</Price>"+
    "</Item>"+
    "<Item>"+
    "<Part>8i Doc Set</Part>"+
    "<Price>350</Price>"+
    "</Item>"+
    "</PurchaseOrder>";
    pStmt.setString(1, xmldoc);
    i got this error
    java.sql.SQLException: ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00240: element-start tag is not well formed
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 301
    ORA-06512: at line 1
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
         at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
         at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
         at xml_tab.doInsert(xml_tab.java:118)
         at xml_tab.main(xml_tab.java:138)
    could you help me?
    Olidong

  • Simple xerces DOMParser.  Why won't this validate? Very simple, xml schema

    I have written a java program called "Validate.java" to validate an xml file. The program uses the xerces DOMParser. When I try and validate a correct .xml file with a correct schema in an .xsd file I get the following errors:
    [Error] Document is invalid: no grammar found. line 2 column 6 - name5.xml
    [Error] Document root element "name", must match DOCTYPE root "null". line 2 column 6 - name5.xmlThe XML file, the XSD file, and the Validate.java program are all in the same directory. My CLASSPATH includes xml-apis.jar, xercesImpl.jar, and xercesSamples.jar.
    Here is the xml file (name5.xml):
    <?xml version="1.0"?>
    <name
        xmlns="http://www.myOwnURL.net/name"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.myOwnURL.net/name name5.xsd"
        title="Mr.">
      <first>John</first>
      <middle>Fitzgerald</middle>
      <last>Doe</last>
    </name>(I saved the file in the UTF-8 encoding, which causes it to look double spaced in some text editors.)
    The schema is in the following xsd file (name5.xsd):
    <?xml version="1.0"?>
    <schema
        xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.myOwnURL.net/name"
        xmlns:target="http://www.myOwnURL.net/name"
        elementFormDefault="qualified">
      <element name="name">
        <complexType>
          <sequence>
            <element name="first" type="string"/>
            <element name="middle" type="string"/>
            <element name="last" type="string"/>
          </sequence>
          <attribute name="title" type="string"/>
        </complexType>
      </element>
    </schema>(Again, the file is saved in UTF-8 format.)
    Here is the code for Validate.java:
    public class Validate implements org.xml.sax.ErrorHandler
        private String instance = null;
        private int warnings = 0;
        private int errors = 0;
        private int fatalErrors = 0;
        private org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser();
        public Validate() // constructor
            parser.setErrorHandler(this); // Set the errorHandler
        public void setInstance(String s)
            instance = s;
        public boolean doValidate()
            try
                warnings = 0;
                errors = 0;
                fatalErrors = 0;
                try
                    // Turn the validation feature on
                    parser.setFeature( "http://xml.org/sax/features/validation", true);
                    // Parse and validate
                    System.out.println("Validating source document...");
                    parser.parse(instance);
                    // We parsed... let's give some summary info of what we did
                    System.out.println("\nComplete " + warnings + " warnings " + errors + " errors " + fatalErrors + " fatal errors");
                    // Return true if we made it this far with no errors
                    return ((errors == 0) && (fatalErrors == 0));
                catch (org.xml.sax.SAXException e)
                    System.err.println("\nCould not activate validation features - " + e.getMessage());
                    return false;
            catch (Exception e)
                System.err.println("\n"+e.getMessage());
                return false;
        public void warning(org.xml.sax.SAXParseException ex)
            System.err.println("\n[Warning] " + ex.getMessage() + " line " + ex.getLineNumber()
            + " column " + ex.getColumnNumber() + " - " + instance);
            warnings++;
        public void error(org.xml.sax.SAXParseException ex)
            System.err.println("\n[Error] " + ex.getMessage() + " line " + ex.getLineNumber()
            + " column " + ex.getColumnNumber() + " - " + instance);
            errors++;
        public void fatalError(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException
            System.err.println("\n[Fatal Error] " + ex.getMessage() + " line " + ex.getLineNumber()
            + " column " + ex.getColumnNumber() + " - " + instance);
            fatalErrors++;
            throw ex;
        public static void main(String[] args)
            Validate validate1 = new Validate();
            if (args.length == 0)
                System.out.println("Usage : java Validate <instance>");
                return;
            // Set the instance
            if (args.length >= 1) validate1.setInstance(args[0]);
            // Validate (the doValidate returns either true or false depending on
            // whether there were any errors.)
            if (!validate1.doValidate()) return;
    }My question is: why do I get those errors??? Why doesn't everything just validate like it is supposed to??? Also, why does the error even mention DOCTYPE -- I thought that was for DTDs, and I am using XML Schema.
    I will be very grateful to anyone who can tell me what is going on here.
    Thanks,
    Jon

    I have solved my problem. I just needed to add the following line to my java program:
    parser.setFeature("http://apache.org/xml/features/validation/schema", true);I'm still not sure how I was supposed to know this, however. I guess spending three hours searching on google is what you are supposed to do. Also, I was thrown for a bit of a loop by the following official faq found at http://xml.apache.org/xerces2-j/faq-pcfp.html:
    [faq]
    Question: How can I tell the parser to validate against XML Schema and not to report DTD validation errors?
    Answer: Currently this is impossible. We hope that JAXP 1.2 will provide this capability via its schema language property. Otherwise, we might introduce a Xerces language property that will allow specifying the language against which validation will occur.
    [faq]
    I am very new to XML (less than a week), but that FAQ sure makes it sound like using only XML Schema and completely avoiding DTDs is impossible. On the other hand, I think that is what I was able to achieve by adding the above line to my code.
    Oh well.
    Jon

  • Validate XML using XSD (XML Schema)

    Hi experts.
    Is there any way in ABAP to validate XML file against specified XSD file?
    I found only possibility to validate against DTD, but no XSD. As far as I know this is only possible in Java, or is a part of XI. Is it doable without Java or XI (on NetWeaver 2004s)?
    Help appreciated (and rewarded).
    Regards, Frantisek.

    Hello
    Perhaps you missed this link: [How to Perform XML Validations in SAP NetWeaver Process Integration 7.1|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d06dff94-9913-2b10-6f82-9717d9f83df1]
    Regards
      Uwe

  • Can't validate against XML Schema take 2

    Hi,
    A few weeks ago I posted a message asking how an XML Schema file should be deployed
    in a web application. During 15 days I recived a lot of replies to questions I
    didn't ask but none to the question I asked. I recall that the XML Schema file
    is deployed with the web application in WEB-INF. I tried also WEB-INF/classes
    and WEB_INF/lib. The XML SChema file is not found. So I'm asking again: how is
    one supposed to deploy an XML Schema file in a Web application ?
    Kind regards,
    Nicolas DUMINIL

    Hi :-)
    Yes it does, in the DomHandler.java it serializes to XML then does the
    reparse with validation.
    BTW, I realized that I left out of the zip the xsd file. It is
    attached. Note also the bar.xml is using this schema from
    http://localhost
    You also have another alternative: employ a parser-specific extension to
    do the revalidation. Xerces' extension appears to be early support for
    nonfinal DOM Level 3, which supports this as part of "normalizing" a DOM
    tree. See http://xml.apache.org/xerces2-j/faq-dom.html#faq-7.
    Good luck in your continuing efforts,
    Bruce
    Nicolas DUMINIL wrote:
    >
    Bruce,
    The example you attached doesn't do any schema validation, as you seem thinking.
    In order to do schema validation, one needs at least a schema, as an XSD file.
    Or the example you provided doesn't contain any schema, at least I didn't see
    any, maybe I'm blind. The example you provided is only doing parsing and, consequently,
    it doesn't have anything to do with the problem I posted. Thank you for your time
    but honestly, don't feel obligated to just reply anything if you don't have the
    answer or you don't understand the problem.
    Kind regards,
    Nicolas DUMINIL
    Bruce Stephens <[email protected]> wrote:
    Hello,
    To obtain information from our outstanding support team you need to open
    a communication dialog using the support portal or email. The
    newsgroups are informally maintained by volunteers (typically
    development engineers), are not maintained by customer support, and
    provide no guarantee for response time or problem resolution.
    Attached is a simple web service example that does schema validation.
    See if this works OK in your environment.
    Hope this is of some value,
    Bruce
    Nicolas DUMINIL wrote:
    I went on http://support.bea.com but there is no any usefull information.
    I took
    a look in the examples you suggested and I found out that it simplydoesn't have
    anything to do with the problem I mentioned. My problem is validatingXML documents
    against an XML Schema. As I repeted at least 10 times:
    1. I know how to parse XML documents.
    2. I know how to use DTDs in validating XML documents.
    3. I also have all the information concerning the XML Schema validationand I
    know how to configure the parser for that.
    The problem I have is that my XML Schema deployed with the applicationis not
    found. It i not on the CLASSPATH, it is deployed with the applicationas any application
    component.
    Kr,
    Nicolas DUMINIL
    Bruce Stephens <[email protected]> wrote:
    Hello,
    Since this has been an ongoing issue, the best solution at this point
    may be to open a dialog with our outstanding support group:
    http://support.bea.com or [email protected]
    BTW, you also may want to take a quick look at the example provided:
    http://dev2dev.bea.com/codelibrary/code/examples_xml.jsp
    Hope this is of some value,
    Bruce
    Nicolas DUMINIL wrote:
    Hi,
    A few weeks ago I posted a message asking how an XML Schema file
    should
    be deployed
    in a web application. During 15 days I recived a lot of replies
    to
    questions I
    didn't ask but none to the question I asked. I recall that the XMLSchema file
    is deployed with the web application in WEB-INF. I tried also WEB-INF/classes
    and WEB_INF/lib. The XML SChema file is not found. So I'm asking
    again:
    how is
    one supposed to deploy an XML Schema file in a Web application ?
    Kind regards,
    Nicolas DUMINIL
    [simple.xsd]

Maybe you are looking for

  • How can i update an html web page from Labview?

    I intend to publish the "status" of an experiment online through an web page. I mean, if my vi is running i would like to have a phrase or indicator set on at my web page. If my Vi is not running i would like this indicator set off. This page is host

  • How do I print more than one custom-size photo on a page in PSE 10?

    I recently upgraded from Photoshop Elements 6 to Photoshop Elements 10.  I make greeting cards, and on PSE 6 I was able to print two custom-size (6-1/2" x 5") cards on each 8-1/2" x 11" sheet of photo paper.  The option to print more than one custom-

  • Does not show anything in Flow tab in Interface

    Hi, I am new in ODI and doing File to File data transformation. I have done this successfully. But here I used Global Context. Instead of Global Context of I used my own Context that I have created in the Overview tab of interface the source , stagin

  • Can't save Photoshop file as a PDF

    The file is RGB and 8-bit, but it is a really large document (144 x 24 inches). When I go to Save As > No PDF option shows up...see screenshot.

  • Hi experts i have doubt in transports...................

    Hi, There are two types of  SLD's  one is centralized and decentralized so for which we need transports and how to transport the sld objects Thanks in advance Ram vijay