  | |  | "standalone " in the XML declaration, <?xml ... ? > | "standalone " in the XML declaration, <?xml ... ? > 2003-05-11 - By Pae Choi
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2600.0" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT size=2>When I try to get the "standalone" attribute value from the DOM after loading</FONT></DIV> <DIV><FONT size=2>the XML document from a file it *always* returns "false."</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>I have a demo XML file containing two lines as:</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>// ################ XML File ##################</FONT></DIV> <DIV><FONT size=2><?xml version="1.0" encoding="UTF-8" standalone="yes"?><BR><xs:schema xmlns:xs="<A href='http://www.w3.org/2001/XMLSchema"/'>http://www.w3.org/2001/XMLSchema"/</A >><BR></FONT></DIV> <DIV><FONT size=2>And the code snippet is as follows:</DIV></FONT> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>// ################ CODE SNIPPET ##################</FONT></DIV> <DIV><FONT size=2>private void checkXMLDecl() {</FONT></DIV> <DIV><FONT size=2> // Create a factory object for creating DOM parsers<BR> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();<BR> DocumentBuilder builder = null;<BR> Document   ; xmlDOM = null;</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2> try {<BR> // Now use the factory to create a DOM parser<BR> builder = factory.newDocumentBuilder();<BR> xsDOM = builder.parse(xsdFile);</FONT></DIV><FONT size=2> <DIV><BR> // Get the xml declaration <BR> System.out.println("version = [" + ((CoreDocumentImpl)xsDOM).getVersion() + "]");<BR> System.out.println("encoding = [" + ((CoreDocumentImpl)xsDOM).getEncoding() + "]");</DIV> <DIV> // ########################################################<BR> // The getStandalone() method does NOT work</DIV> <DIV> if ( ((CoreDocumentImpl)xsDOM).getStandalone() )<BR> System.out.println("standalone is true");<BR> else<BR> System.out.println("standalone is false");<BR> }</DIV> <DIV> catch (Exception ex) {</DIV> <DIV> }</DIV> <DIV>}</DIV> <DIV> </DIV> <DIV>I have tested with Xerces v2.0.2, v2.2.1, and v2.4.0, but all three returns</DIV> <DIV>the same result, "false."</DIV> <DIV> </DIV> <DIV>Any comments?</DIV> <DIV> </DIV> <DIV> </DIV> <DIV>Pae</DIV> <DIV> </DIV></FONT></BODY></HTML>
|
|
 |