1

I have a file which contains a list of xmls , one on each line. When I try to parse this file using the code given here:

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);

I get parsing error when my file looks like this(multiple xmls, say File1)-

<T1>  
    <T2>    
        <T4>        
            <T3>TEST</T3>   
        </T4>  
    </T2>   
    <T5>    
        <TID>NEwid:0</TID>  
    </T5> 
</T1>
<T1>  
    <T2>    
        <T4>        
            <T3>TEST</T3>   
        </T4>  
    </T2>   
    <T5>    
        <TID>NEwid:1</TID>  
    </T5> 
</T1>

However, following file parses successfully(single xml, say File2)

<T1>  
    <T2>    
        <T4>        
            <T3>TEST</T3>   
        </T4>  
    </T2>   
    <T5>    
        <TID>NEwid:0</TID>  
    </T5> 
</T1>

My requirement is that I need to replace the value of tag in each of the xmls which will be present in a single file(the file format will be like File1 ).Am not sure if File1 is even a proper xml , but that is how the file is like. I am able to replace the value of when I place only one xml in a file . (Have used the best answer stated here: How to update xml files in java)

Manas Saxena
  • 2,171
  • 6
  • 39
  • 58

0 Answers0