SSISO Community

시소당

XML파일을 분석하고 있는 동안 주석 무시

By  default,  Comment  nodes  are  created  for  each  comment  in  an  XML  file.  If  it  is  not  necessary  to  preserve  the  
comments,  there  is  no  need  to  create  the  nodes.  This  example  demonstrates  how  to  create  a  parser  that  ignores  
comments.

        try  {
                //  Create  a  builder  factory
                DocumentBuilderFactory  factory  =  DocumentBuilderFactory.newInstance();
        
                //  Configure  it  to  ignore  comments
                factory.setIgnoringComments(true);
        
                //  Create  the  builder  and  parse  the  file
                Document  doc  =  factory.newDocumentBuilder().parse(new  File("infilename.xml"));
        
                //  doc  will  not  contain  any  Comment  nodes
        }  catch  (SAXException  e)  {
                //  A  parsing  error  occurred;  the  xml  input  is  not  valid
        }  catch  (ParserConfigurationException  e)  {
        }  catch  (IOException  e)  {
        }

Here's  some  sample  input:

        <?xml  version="1.0"  encoding="UTF-8"?>
        <!--  comment  -->
        <root>
                Some  text
                <!--  comment  -->
                Some  text
        </root>
        <!--  comment  -->

and  output:

        <?xml  version="1.0"  encoding="UTF-8"?>
        <root>
                Some  text
        
                Some  text
        </root>

[2008년  03월  11일  17:40:33  수정되었습니다.]

780 view

4.0 stars