You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Kapa, Madhavi" <ma...@marconimed.com> on 2000/08/25 16:04:16 UTC

Bug, maybe in setIncludeIgnorableWhitespace(boolean) function of the Xerces parser

Hi,

  Versions of software used 
  Xerces parser          Version 1.0.3
  JDK                    Version 1.2


  I am trying to parse an XML file into a DOM tree and then access the nodes
in the DOM tree.
  
  My question is about the parser's ability to ignore whitespaces in an XML
file, when I set parser.setIncludeIgnorableWhitespace(false);      

                            Please reply to madhavi.kapa@marconimed.com as I
am still not able to access the mailing lists

  Details : 

  My xml file looks like this (servletConfig.xml) : 

  <?xml version="1.0"?>
<allActions>
  <action>
      <name> login </name>
      <stylesheet>
          <name> login.xsl </name>
          <styleset> marconi </styleset>
      </stylesheet>
  </action>
  <action>
      <name> error </name>
      <stylesheet>
        <name> error.xsl </name>
        <styleset> marconi </styleset>
      </stylesheet>
  </action>
</allActions>


  And the way I parse the XML file is 
  
    String xmlFile = "servletConfig.xml";               // Name of the XML
file
    DOMParser parser = new DOMParser();         // Create the parser object
    Document document = null;                          // Document object

    parser.setIncludeIgnorableWhitespace(false);          // Set the parser
to ignore the whitespace nodes in the DOM obtained after parsing
    parser.parse(xmlFile);                                           //
Parse the XML file
    document = parser.getDocument();                        // Get the DOM 
			
		
    Node n = document.getFirstChild();                           // Get the
first child of the DOM
    System.out.println("Name = " + n.getNodeName());    // Print out the
name of the node, n

    Node n1 = n.getFirstChild();                                        //
Get the first child of the node n
    System.out.println("Name = " + n1.getNodeName());    // Print out the
name of the node, n1
    System.out.println("Value = " + n1.getNodeValue());     // Print out the
value of the node, n1

    Node n2 = n1.getNextSibling();
// Get the next sibling of the node n1
    System.out.println("Name = " + n2.getNodeName());           // Print out
the name of the node, n2
    System.out.println("Value = " + n2.getNodeValue());           // Print
out the value of the node, n2


The output is 
  Name = allActions
  Name = #Text
  Value = 
  Name = action
  Value = null

My question is although I set up the parser to ignore whitespaces and not
include them as text nodes in the DOM, it still does that. Is this a bug?

Thanks,
Madhavi