这里面包含了一百多个JAVA源文件

源代码在线查看: e515. ignoring comments while parsing an xml file.txt

软件大小: 551 K
上传用户: maple_78
关键词: JAVA
下载地址: 免注册下载 普通下载 VIP

相关代码

				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: 
				    
				    
				    
				        Some text
				        
				        Some text
				    
				    
				
				and output: 
				    
				    
				        Some text
				    
				        Some text
				    
				
							

相关资源