logo       

Re: XML Validation of root node: msg#00004

Subject: Re: XML Validation of root node
Thanks guys, for helping out. 

I find that setting the Feature
"http://apache.org/xml/features/validation/dynamic"; to True causes
this problem to happen. If I keep this flag to false, the incorrect
root node is properly identified. If the flag is True, it does not
catch the incorrect root node.

Any idea why this happens? 


Here's the code: 

        SAXParser par = new SAXParser ();
        par.setErrorHandler(new ParserErrorHandler()); //
ParserErrorHandler and ParserEntityResolver are trivial classes..
nothing significant there..
        par.setEntityResolver(new ParserEntityResolver());
        try
        {
            par.setFeature("http://xml.org/sax/features/validation";, true);
            par.setFeature("http://apache.org/xml/features/validation/schema";,
true);
            par.setFeature("http://apache.org/xml/features/validation/dynamic";,
true); // This is the problem!!

            FileInputStream fis = new FileInputStream
("D:/cdcatalog_invalid.xml");
            ProtectedInputStream pis = new ProtectedInputStream(fis);
            InputSource is = new InputSource (pis);
            par.parse(is);
        }
        catch (Exception e)
        { }

        public class ProtectedInputStream extends InputStream {
            private InputStream is;
            public ProtectedInputStream(InputStream is) {
                this.is = is;
            }
            public int read() throws IOException {
                return is.read();
            }
            public void close() { // Overridden close function to prevent
Xerces from closing my stream
            }
        }


Thanks, 
Subbu. 


On Wed, 26 Jan 2005 15:13:45 -0700, Wax, Ed <Ed_Wax@xxxxxxxxxxxxxx> wrote:
>  
> 
> Subbu, 
> 
> I have a Xerces-based (J-2.6.2) validator.  It would appear my validation
> runs differ from yours.  
> 
> Validating the <catalog_abc123 ...> instance document shown below (which you
> state is OK by Xerces): 
> 
> command line is: -p org.apache.xerces.parsers.XML11Configuration -s
> ../temp/cdcatalog.xsd -i ../temp/cdcatalog1.xml 
> setting parser configuration ... 
> parser configuration is: org.apache.xerces.parsers.XML11Configuration 
> setting schema support ... 
> adding schema: ../temp/cdcatalog.xsd to the list ... 
> adding instance file: ../temp/cdcatalog1.xml to the list ... 
> registering the XML_SCHEMA grammar ... 
> parsing ../temp/cdcatalog.xsd ... 
> ... done (schema conforms to W3C spec) 
> Validating XML instance documents ... 
> Validating ../temp/cdcatalog1.xml ... 
> [Error] cdcatalog1.xml:2:47: cvc-elt.1: Cannot find the declaration of
> element 'catalog_abc123'. 
> ... found some error(s) 
> 
> Validating the <catalog ...> instance document shown below (which you state
> is in err by Xerces): 
> 
> command line is: -p org.apache.xerces.parsers.XML11Configuration -s
> ../temp/cdcatalog.xsd -i ../temp/cdcatalog2.xml 
> setting parser configuration ... 
> parser configuration is: org.apache.xerces.parsers.XML11Configuration 
> setting schema support ... 
> adding schema: ../temp/cdcatalog.xsd to the list ... 
> adding instance file: ../temp/cdcatalog2.xml to the list ... 
> registering the XML_SCHEMA grammar ... 
> parsing ../temp/cdcatalog.xsd ... 
> ... done (schema conforms to W3C spec) 
> Validating XML instance documents ... 
> Validating ../temp/cdcatalog2.xml ... 
> ... done (instance document is VALID) 
> 
> Regards, 
> Ed 
>  
> 
> -----Original Message----- 
> From: Subbu Iyer [mailto:subbdi@xxxxxxxxx] 
> Sent: Wednesday, January 26, 2005 2:33 PM 
> To: xerces-j-user@xxxxxxxxxxxxxx 
> Subject: XML Validation of root node 
> 
> 
>  
>  
> 
> Hi, 
> 
> I am trying to validate the following XML using Xerces 2.5 (also tried 
> with latest 2.6 version). I notice that if the root node is incorrect, 
> the message still gets validated successfully without any errors. 
> However, if any element within the document is incorrect, the XML is 
> reported to be invalid. 
> 
> This is the original correct XML doc. 
> 
> <catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xsi:noNamespaceSchemaLocation="cdcatalog.xsd"> 
>         <cd> 
>                 <title>Empire Burlesque</title> 
>                 <artist>Bob Dylan</artist> 
>                 <country>USA</country> 
>                 <company>Columbia</company> 
>                 <price>10.90</price> 
>                 <year>1985</year> 
>         </cd> 
> </catalog> 
> 
> This following XML is NOT reported by Xerces to be invalid though the 
> root element is incorrect. 
> 
> <catalog_abc123 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xsi:noNamespaceSchemaLocation="cdcatalog.xsd"> 
>         <cd> 
>                 <title>Empire Burlesque</title> 
>                 <artist>Bob Dylan</artist> 
>                 <country>USA</country> 
>                 <company>Columbia</company> 
>                 <price>10.90</price> 
>                 <year>1985</year> 
>         </cd> 
> </catalog_abc123> 
>  
> 
> However, the following XML is correctly reported to be invalid. 
> 
> <catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xsi:noNamespaceSchemaLocation="cdcatalog.xsd"> 
>         <cd> 
>                 <bad_title>Empire Burlesque</bad_title> <!-- Invalid element
> --> 
>                 <artist>Bob Dylan</artist> 
>                 <country>USA</country> 
>                 <company>Columbia</company> 
>                 <price>10.90</price> 
>                 <year>1985</year> 
>         </cd> 
> </catalog> 
>  
> 
> The XSD (cdcatalog.xsd) is attached with this mail. 
> 
> Any ideas on what could be wrong? 
> 
> Thanks, 
> Subbu. << File: cdcatalog.xsd >>  << File: ATT34260.txt >>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe