Validate xml with local dtd

hello
trying to write a unit test that validates some xml we are marshalling against a dtd. here is a snippet of code. The problem is how to specify the dtd against which the xml is to be validated. verification_transaction is our root xml element. when i run this code i get a
malformedurlexception: no protocol: verification.dtd
any ideas?
                StringWriter writer = new StringWriter();
               // write the doctype declaration
                writer.write("<!DOCTYPE verification_transaction SYSTEM \"verification.dtd\">");
                // now marshal to the writer
          marshaller.marshal(spec, requestType, componentNumber, writer);
          InputStream inputStream = new ByteArrayInputStream(writer.getBuffer().toString().getBytes());
          Reader reader = new InputStreamReader(inputStream);
                // get a sax parser that is validating
          TestHandler handler = new TestHandler();
          SAXParserFactory factory = SAXParserFactory.newInstance();
          factory.setValidating(true);
          SAXParser saxParser = factory.newSAXParser();
          try {
               saxParser.parse(new InputSource(reader), handler);
               fail("Should have thrown exception.");
          } catch (RuntimeException e) {
               // pass
          }Message was edited by:
shrndegruv

I needed to do a bunch of things.
1.
                URL url = getClass().getResource("/verification.dtd");
          StringWriter writer = new StringWriter();
          writer.write("<?xml version=\"1.0\"?><!DOCTYPE verification_transaction SYSTEM \"" + url + "\">");and then I had to use a handler which processed the errors (which I got from an online tutorial):
private static class MyErrorHandler extends DefaultHandler {
          public void warning(SAXParseException e) throws SAXException {
               System.out.println("Warning: ");
               printInfo(e);
          public void error(SAXParseException e) throws SAXException {
               System.out.println("Error: ");
               printInfo(e);
               throw new SAXException("DTD Validation Error: [" + e.getMessage() + "]");
          public void fatalError(SAXParseException e) throws SAXException {
               System.out.println("Fatal error: ");
               printInfo(e);
          private void printInfo(SAXParseException e) {
               System.out.println("   Public ID: " + e.getPublicId());
               System.out.println("   System ID: " + e.getSystemId());
               System.out.println("   Line number: " + e.getLineNumber());
               System.out.println("   Column number: " + e.getColumnNumber());
               System.out.println("   Message: " + e.getMessage());
     }

Similar Messages

  • Validate xml with PL/SQL Parser

    Hi,
    i have an xml DTD into a VARCHAR2 variable and an xml document
    into a CLOB, i'd like to know how to validate the xml with my
    DTD using PL/SQL API for xml.
    Sorry for my terrible english (i'm not english) :-)
    Tank you.

    Here's an example:
    set serveroutput on
    DECLARE
      p xmlparser.parser;
      d xmldom.DOMDocument;
      dtd xmldom.DOMDocumentType;
      v varchar2(32700);
      good clob;
      bad clob;
      xml_parse_error exception;
      pragma exception_init(xml_parse_error,-20100);
    BEGIN
      bad   := '<!DOCTYPE Department SYSTEM "test.dtd"><Deprtment/>';
      good  := '<!DOCTYPE Department
    SYSTEM "test.dtd"><Department/>';
      v := '<!ELEMENT Department EMPTY>';
      p := xmlparser.newParser;
      xmlparser.parseDTDBuffer(p,v,'Department');
      xmlparser.setDoctype(p,xmlparser.getDoctype(p));
      xmlparser.setValidationMode(p,TRUE);
      xmlparser.parseClob(p,good);
      xmlparser.parseClob(p,bad);
      xmlparser.freeParser (p);
    EXCEPTION
      WHEN xml_parse_error THEN
         DBMS_OUTPUT.PUT_LINE(sqlerrm);
         xmlparser.freeParser (p);
    END;

  • 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.

  • Validating XML with its DTD in JSP

    Is there a way to validate an XML file with its DTD, using a JSP ???
    If YES, then HOW???
    I hope my question is clear enough.
    Please help!!

    Thanks "Jleech",
    I am using a textarea in a JSP to input for an XML file. The JSP transfers the file to Web-Server, which also has XERCES installed. My question is how can u Validate this transfered XML file with its DTD. My problem is I don't to how to include that Validation program in JSP.?
    Could you still help???

  • Validate XML against  one DTD

    Hello
    I have several XML files and into this XML files there is not th DTD call.
    i have another file, the DTD.
    There is any method or code example for, without modify the XML files for including the DTD call, validate the XML againts one DTD?
    thanks

    Alice (guest) wrote:
    : Hi! I have obtained the v2 parser for java and the one for
    plsql.
    : I want to validate xml documents against a DTD file provided
    by
    : another program. I can't find any sample code that does setDTD
    : for validation.
    : Can you tell me how it can be done, please?
    : Thanks in advance!
    The method to set the DTD is setDoctype().
    Stub code follows:
    // Test using InputSource
    parser = new DOMParser();
    parser.setErrorStream(System.out);
    parser.showWarnings(true);
    FileReader r = new FileReader(args[0]);
    InputSource inSource = new InputSource(r);
    inSource.setSystemId(createURL(args[0]).toString());
    parser.parseDTD(inSource, args[1]);
    dtd = (DTD)parser.getDoctype();
    r = new FileReader(args[2]);
    inSource = new InputSource(r);
    inSource.setSystemId(createURL(args[2]).toString());
    parser.setDoctype(dtd);
    parser.setValidationMode(true);
    parser.parse(inSource);
    doc = (XMLDocument)parser.getDocument();
    doc.print(new PrintWriter(System.out));
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • Validate XML document (no DTD reference)

    Hi,
    I have two files: document.xml and rules.dtd. My "document.xml" does not reference "rules.dtd", but I would like to validate basead on this file. Is it possible?
    Is there a method like: boolean isValid(String xmlFile, String dtdFile) ?
    Thanks,
    Andr�

    Add a <!DOCTYPE root_element SYSTEM "dtdFile.dtd"> to the xml document.

  • 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>

  • ORA-31020 when using XML with external DTD or entities

    I'd like to parse XML documents against a modular DTD that references other DTDs. This works fine with Oracle 9i. But after upgrading to 11g, the parsing of XML-instances fails and DBMS_XMLPARSER.parseClob produces ORA-31020.
    The same error occurs even if I simply try to store XML with a reference to an external DTD as xmltype:
    SQL> select xmltype('<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE ewl-artikel SYSTEM "http://www.foo.com/example.dtd"><test>123</test>') from dual;
    ERROR:
    ORA-31020: Der Vorgang ist nicht zulässig, Ursache: For security reasons, ftp
    and http access over XDB repository is not allowed on server side
    ORA-06512: in "SYS.XMLTYPE", Zeile 310
    ORA-06512: in Zeile 1
    How can I use external DTDs on remote servers in order to parse XML in an 11g database??? Any ideas for a workaround? Thanks in advance!

    This is my PL/SQL validation procedure:
    procedure validatexml (v_id in number default 0) is
    PARSER DBMS_XMLPARSER.parser;
    DTD_SOURCE clob;
    DTD_DOCUMENT xmldom.DOMDocumentType;
    XML_INSTANCE xmltype;
    BEGIN
    -- load DTD from XDB repository
    SELECT httpuritype('http://example.foo.de/app1/DTD1.dtd').getclob() into DTD_SOURCE from dual;
    -- load XML instance
    select co_xml into XML_INSTANCE from tb_xmltab where co_id=v_id;
    -- parse XML instance
    PARSER := DBMS_XMLPARSER.newParser;
    xmlparser.setValidationMode( PARSER , false);
    xmlparser.parseDTDClob( PARSER , DTD_SOURCE , 'myfirstnode' );
    DTD_DOCUMENT := xmlparser.getDoctype( PARSER );
    xmlparser.setValidationMode( PARSER , true );
    xmlparser.setDoctype( PARSER , DTD_DOCUMENT );
    DBMS_XMLPARSER.parseClob( PARSER , v_xml );
    DBMS_XMLPARSER.freeParser(PARSER);
    htp.print('<P>XML instance succesfully validated!<P>');
    end validatexml;

  • Validate XML with XSD Puntuaction Marks

    Hello all,
    I am trying to validate a XML document against a registered XML schema. The XML document contains punctuation marks (like ã, ç, õ) which cause the validation to fail. How to overcome this?
    I suspect of the encoding format the XSD and XML documents are using, encoding=UTF-8, right?
    Thank you,
    Pedro.

    Ok... just needed to change the enconding attribute of the XML document to the value of the parameter NLS_CHARACTERSET of my database.
    Unnecessary post. :-o)

  • Validate XML with multiple XML Sechme in the same namespace

    In my program, i use multiple xml schemas to validate against my xml files.
    However, i found the following code do not work because all schemas in the same namespace.
    Does any one have some solutions to validate multiple XML Schemas in the same namespace?
    Thanks~~
    static final String[] schemas = { partyInformationSchema,
    itemInformationSchema,
    exceptionsSchema,
    salesForecastSchema,
    exceptionCriteriaSchema };
    factory.setAttribute(JAXP_SCHEMA_SOURCE, schemas);

    I have used the Object arrsy too, but it didn't work.
    static final Object[] schemas = { partyInformationSchema,
    itemInformationSchema,
    exceptionsSchema,
    salesForecastSchema,
    exceptionCriteriaSchema };

  • Validating XML with external dtd without doctype specified in xml

    Hi,
    I am very new to SAX, DOM and things..but I am really pulling my hair to find the soln., I have tried to search soln but I found many people asking same question but hardly anyone was satisfactory.
    My problem is that I have xml file without doctype specified in it, but I have dtd available on my system.
    I have tried to set MyEntityResolver which implements EntityResolver in documentBuilder but its only getting called (resolveEntity method of MyEntirtyResolver), only when I add doctype to the xml (which is not what I want) and not when there is no doctype in the xml. I have set "factory.setValidating(true)" and I also have errorHandler in place.
    But why EntityResolver is not invoked when its needed most. ie. when doctype is not available in xml ?...it complains that DOCTYPE must match root=null , which is obvious because no DOCTYPE in xml.
    code is as follows:
    please help me ..if anyone has any idea about this ....
    Main class is :
    public static void main(String args[]){
              Document document=null;
              ErrorHandler defaultHandler=new MyDefaultHandler();
              String xmlFile="note.xml";
              try{
                   System.out.println("Starting...");
                 boolean validXML = true;
                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                 factory.setNamespaceAware(true);
                 factory.setValidating(true);
                 try {
                    ExternalResolver er = new ExternalResolver();
    // addURL is just a method which sets string in a map to be retrieved by resolveEntiy
                    er.addURL("D:\\SAXnDOM\\SAXProject\\note.dtd");
                    DocumentBuilder builder = factory.newDocumentBuilder();
                     builder.setEntityResolver(er);
                     builder.setErrorHandler(new MyDefaultHandler());
                    builder.parse(new File(xmlFile));
                 resolveEntity of ExternalResolver is as follows:
    public InputSource resolveEntity(String publicId, String systemId)
                   throws SAXException, IOException {
               System.out.println("********resolvedEntity:" +publicId +" and "+systemId +"******");
             if ( urlMap != null && urlMap.get(systemId)!= null ){
                 try {
                     return new InputSource(new FileReader(systemId));
                 } catch (FileNotFoundException e) {
                     System.out.println("[ERROR] Unable to load entity reference: " + systemId );
             return null;
    public void addURL(String filePath) throws MalformedURLException{
              addURL(new File(filePath).toURL());
         public void addURL(URL url) {
             if ( urlMap == null ){
                 urlMap = new HashMap();
             urlMap.put(url, null);
         }

    Its working.... its working ...
    problem was in resolveEntity, that stupid if condition was removed like this:
    public InputSource resolveEntity(String publicId, String systemId)
                   throws SAXException, IOException {
               System.out.println("********resolvedEntity:" +publicId +" and "+systemId +"******");
                try {
                     return new InputSource("D:\\SAXnDOM\\SAXProject\\note.dtd");
                 } catch (Exception e) {
                     System.out.println("[ERROR] Unable to load entity reference: " + systemId );
             return null;
         }Other change is (which I didnt like ) is that in my xml, I had written fake doctype like :
    <?xml version="1.0"?>
    <!DOCTYPE note SYSTEM "fakenote.dtd">
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    <Prashant>prdfjfdj</Prashant>
    </note> in above code fakenote.dtd doesnt exist anywhere ..its just to bypass that doctype:null error.
    So my guess is that EntityResolver overrides doctype in the xml and applies its own doctype (note.dtd in this case)
    But new proble comes...what if i dont want to add any doctype ..not even fake in xml ?
    Hope my stupid mistakes will find someone usefull..

  • Validate XML with XSD

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    with the partitioning, real application clusters, olap, data mining
    and Real Application Testing options
    Working with relational tables containing clob type columns (no XMLDB available) I'm not able to set up a simple validation example as below (supposed to return 1 confirming a successful validation).
    declare
      xmldoc xmltype;
      sb_xml xmltype;
      valid_ number;
      xmlxsd varchar2(4000) := q'~<?xml version="1.0" ?>
                                  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
                                  <xs:element name="greeting" type="xs:string" />
                                  </xs:schema>~';
      xmlxml varchar2(32767) := q'~<?xml version="1.0" ?><greeting>"HELLO !"</greeting>~';
    begin
      xmldoc := xmltype(xmlxml);
      sb_xml := xmldoc.createschemabasedxml();
      valid_ := sb_xml.isschemavalid(xmlxsd);
      dbms_output.put_line('IsSchemaValid (0=false,1=true): ' || to_char(valid_));
    end;Thanks in advance for any kind of help provided
    Etbin

    no XMLDB availablenot sure if it will work without xmldb, but you might try to use java for schema validation:
    SQL> CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "SchemaUtil"
      2  as
      3
      4  import oracle.xml.parser.schema.*;
      5  import oracle.xml.parser.v2.*;
      6  import oracle.sql.CHAR;
      7  import java.io.*;
      8
      9  public class SchemaUtil
    10  {
    11     public static String validation(CHAR xml, CHAR xsd)
    12     throws Exception
    13     {
    14        //Build Schema Object
    15        XSDBuilder builder = new XSDBuilder();
    16        byte [] docbytes = xsd.getBytes();
    17        ByteArrayInputStream in = new   ByteArrayInputStream(docbytes);
    18        XMLSchema schemadoc = (XMLSchema)builder.build(in,null);
    19        //Parse the input XML document with Schema Validation
    20        docbytes = xml.getBytes();
    21        in = new ByteArrayInputStream(docbytes);
    22        DOMParser dp  = new DOMParser();
    23        // Set Schema Object for Validation
    24        dp.setXMLSchema(schemadoc);
    25        dp.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    26        dp.setPreserveWhitespace (true);
    27        StringWriter sw = new StringWriter();
    28        dp.setErrorStream (new PrintWriter(sw));
    29        try
    30        {
    31           dp.parse (in);
    32           sw.write("The input XML parsed without errors.\n");
    33        }
    34        catch (XMLParseException pe)
    35        {
    36             sw.write("Parser Exception: " + pe.getMessage());
    37          }
    38        catch (Exception e)
    39          {
    40             sw.write("NonParserException: " + e.getMessage());
    41          }
    42          return sw.toString();
    43     }
    44   }
    45  /
    Java created.
    SQL>
    SQL> create or replace function schemavalidation(xml in varchar2,xsd in varchar2)
      2  return varchar2 is language java name 'SchemaUtil.validation(oracle.sql.CHAR,oracle.sql.CHAR)
      3                   returns java.lang.String';
      4  /
    Function created.
    SQL>
    SQL> select schemavalidation('<?xml version="1.0" ?><greeting>"HELLO !"</greeting>',
      2                           '<?xml version="1.0" ?>
      3                          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      4                          <xs:element name="greeting" type="xs:string" />
      5                          </xs:schema>') schemavalidation from dual
      6  /
    SCHEMAVALIDATION
    The input XML parsed without errors.
    SQL>

  • Validate xml with DOM - no grammar found

    Validation with XmlSpy is OK!
    Please help me. My problem is...
    ==========================================================
    // Schema...
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:complexType name="ParentType">
    <xs:sequence>
    <xs:element name="parent1" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ChildType">
    <xs:complexContent>
    <xs:extension base="ParentType">
    <xs:sequence>
    <xs:element name="child1" type="xs:string"/>
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="element" type="ParentType" maxOccurs="2"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    ==========================================================
    // Xml-file:
    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://pctoiv/etktoiv/Extending.xsd">
    <element xsi:type="ChildType">
    <parent1/>
    <child1/>
    </element>
    <element xsi:type="ParentType">
    <parent1/>
    </element>
    </root>
    =================================================================
    //java code...
    String W3C_XML_SCHEMA = "http://www.w3c.org/2001/XMLSchema";
    String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
    String schemaSource = "http://pctoiv/etktoiv/Extending.xsd";
    javax.xml.parsers.DocumentBuilder documentBuilder = null;
    org.w3c.dom.Document xmlDoc = null;
    javax.xml.parsers.DocumentBuilderFactory docBuildFactory =
    javax.xml.parsers.DocumentBuilderFactory.newInstance();
    docBuildFactory.setNamespaceAware(true);
    docBuildFactory.setValidating(true);
    docBuildFactory.setAttribute(JAXP_SCHEMA_SOURCE, W3C_XML_SCHEMA);
    docBuildFactory.setAttribute( JAXP_SCHEMA_SOURCE, schemaSource);
    documentBuilder = docBuildFactory.newDocumentBuilder();
    documentBuilder.setErrorHandler(new MyErrorHandler(System.out));
    xmlDoc = documentBuilder.parse(new java.io.File("Extending.xml"));
    ================================================
    // And errors...
    org.xml.sax.SAXParseException: Document is invalid: no grammar found.
    org.xml.sax.SAXParseException: Document root element "root", must match DOCTYPE root "null".

    Validation with XmlSpy is OK!
    Please help me. My problem is...
    =======================================================
    ==
    // Schema...
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">
    <xs:complexType name="ParentType">
    <xs:sequence>
    <xs:element name="parent1" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ChildType">
    <xs:complexContent>
    <xs:extension base="ParentType">
    <xs:sequence>
    <xs:element name="child1" type="xs:string"/>
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="element" type="ParentType"
    maxOccurs="2"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    =======================================================
    ==
    // Xml-file:
    <?xml version="1.0" encoding="UTF-8"?>
    <root
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://pctoiv/etktoiv/Ex
    ending.xsd">
    <element xsi:type="ChildType">
    <parent1/>
    <child1/>
    </element>
    <element xsi:type="ParentType">
    <parent1/>
    </element>
    </root>
    =======================================================
    =========
    //java code...
    String W3C_XML_SCHEMA =
    "http://www.w3c.org/2001/XMLSchema";
    String JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    String schemaSource =
    "http://pctoiv/etktoiv/Extending.xsd";
    javax.xml.parsers.DocumentBuilder documentBuilder =
    null;
    org.w3c.dom.Document xmlDoc = null;
    javax.xml.parsers.DocumentBuilderFactory
    docBuildFactory =
    javax.xml.parsers.DocumentBuilderFactory.newInstance();
    docBuildFactory.setNamespaceAware(true);
    docBuildFactory.setValidating(true);
    docBuildFactory.setAttribute(JAXP_SCHEMA_SOURCE,
    W3C_XML_SCHEMA);
    docBuildFactory.setAttribute( JAXP_SCHEMA_SOURCE,
    schemaSource);
    documentBuilder =
    docBuildFactory.newDocumentBuilder();
    documentBuilder.setErrorHandler(new
    MyErrorHandler(System.out));
    xmlDoc = documentBuilder.parse(new
    java.io.File("Extending.xml"));
    ================================================
    // And errors...
    org.xml.sax.SAXParseException: Document is invalid: no
    grammar found.
    org.xml.sax.SAXParseException: Document root element
    "root", must match DOCTYPE root "null".
    Try this:
    private static final String JAXP_SCHEMA_SOURCE
    = "http://java.sun.com/xml/jaxp/properties/schemaSource";
    private static final String JAXP_SCHEMA_LANGUAGE
    = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    private static final String W3C_XML_SCHEMA
    = "http://www.w3.org/2001/XMLSchema";
    docBuildFactory.setNamespaceAware(true);
    docBuildFactory.setValidating(true);
    docBuildFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); // use LANGUAGE here instead of SOURCE
    docBuildFactory.setAttribute( JAXP_SCHEMA_SOURCE, schemaSource);
    documentBuilder = docBuildFactory.newDocumentBuilder();
    Good luck!
    Paul Niedenzu

  • Loading XML with defined DTD

    Hi all!
    I create XML and DTD. All working fine when I open it in MS XMLNotepad.
    But when I try to load my XML in validating mode I get error
    Error opening external DTD 'ReportsDTD.dtd'.
    I open my XML through class loader as resource stream and then load it from this stream.
    In XML I have such string
    <!DOCTYPE DEFINITIONS SYSTEM "ReportsDTD.dtd">
    Both xml and dtd are located in same directory.
    Can anybody explain me whats wrong?
    Mike

    Reading from a stream, the parser has no idea what the "current directory" is.
    So, when you reference a relative URL like "ReportsDTD.dtd", this means to find the DTD in the "same directory" as the current XML document.
    You need to properly set the Base URL of the original input stream so that the parser knows what the base directory is.
    Or, alternatively you can use getResource on the Class object that returns a URL and that has embedded within it the correct base URL "directory" info to work correctly.
    So, if I have a "foo.xml" file that references "foo.dtd" inside, I can use the following code:
    import java.net.URL;
    import oracle.xml.parser.v2.*;
    public class Class1
    public static void main(String[] a) throws Throwable {
    Class1 c = new Class1();
    URL u = c.getClass().getResource("foo.xml");
    DOMParser p = new DOMParser();
    p.parse(u);
    p.getDocument().print(System.out);
    public Class1() { }
    }Steve Muench
    Development Lead, Oracle XSQL Pages Framework
    Lead Product Manager for BC4J and Lead XML Evangelist, Oracle Corp
    Author, Building Oracle XML Applications
    null

  • Validating xml with dtd

    Hi,
             I have found a piece of code through google, to validate an xml file with an external dtd file. which is
               function validateDocument()
                    xmlDocumentObject = new ActiveXObject("microsoft.XMLDOM")
                    xmlDocumentObject.onreadystatechange = changeHandler
                    xmlDocumentObject.load('C:\\My.xml')
                function changeHandler()
               and for that we need to a import i.e  #import "C:\WINDOWS\system32\msxml4.dll"
              here when i try to import "msxml4.dll" in Acrobat javascript (js) file, it is giving error, application exits.
               How can i import dll in Acrobat javascript to get some functionality, or if not
              What someother way to achieve this(To validate xml with dtd file).
             This is totally making me crazy, please someone help me on this issue.
    thanks in advance.

    thanks Leonard,
             But my problem is i have an xml(i created that using acrobat javascript)and a dtd file, i want validate xml file with that dtd, using acrobat or some other way.  How can i validate xml with dtd, please help me.

Maybe you are looking for

  • Wireless and cable network working together

    How do I set up an apple network to allow wireless and ethernet to work simultaneously for different purposes. At our current location we have internet access through a wireless hub but are networking all computers through ethernet. I need to seperat

  • Iphone 4 blue vibrating screen

    just got my iphone 4 today. the phone randomly shut off. i ignored and started it back up . then it did it again and wouldnt turn on. so i hooked up to the computer and it a message came up that it needed to be restored. once it started restoring the

  • JTextField's - setting editable false, but without greying out the area?

    Is this at all possible? Is there any other way to go about it? Or is the only way to make a textfeild un-edditable using the setEditable(false); command.. and sticking it with the grey area? Sorry for the weird/dumb/annoying question.. Thanks anyway

  • Storing Word Documents and pictures in Oracle

    Hi, We are using Oracle 8i and we need to store the Photos and Word documents uploaded from the front end. Can anyone suggest the best way to do so. Thanks in advance fics

  • Manipulating the bank statement EBS

    Hello, i want to change few fields before the EBS is posted to SAP. I want to change the text by truncating it assign a trading partner change the posting rule based on the weather it is CAT D and CAT V and if it is a debit or credit Could anyone hel