When I try to get the "standalone" attribute value from the DOM after loading
the XML document from a file it *always* returns "false."
 
I have a demo XML file containing two lines as:
 
// ################ XML File ##################
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
And the code snippet is as follows:
 
// ################ CODE SNIPPET ##################
private void checkXMLDecl() {
        // Create a factory object for creating DOM parsers
        DocumentBuilderFactory  factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder         builder = null;
        Document                 xmlDOM = null;
 
        try {
            // Now use the factory to create a DOM parser
            builder = factory.newDocumentBuilder();
            xsDOM = builder.parse(xsdFile);

            // Get the xml declaration
            System.out.println("version = [" + ((CoreDocumentImpl)xsDOM).getVersion() + "]");
            System.out.println("encoding = [" + ((CoreDocumentImpl)xsDOM).getEncoding() + "]");
            // ########################################################
            // The getStandalone() method does NOT work
            if ( ((CoreDocumentImpl)xsDOM).getStandalone() )
                System.out.println("standalone is true");
            else
                System.out.println("standalone is false");
        }
        catch (Exception ex) {
        }
}
 
I have tested with Xerces v2.0.2, v2.2.1, and v2.4.0, but all three returns
the same result, "false."
 
Any comments?
 
 
Pae
 

Reply via email to