How do I split a large xml file?

后端 未结 7 2060
小鲜肉
小鲜肉 2021-01-02 14:05

We export “records” to an xml file; one of our customers has complained that the file is too big for their other system to process. Therefore I need to split up the file,

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 14:26

    There's no general-purpose solution to this, because there's so many different possible ways that your source XML could be structured.

    It's reasonably straightforward to build an XSLT transform that will output a slice of an XML document. For instance, given this XML:

    you can output a copy of the file containing only data elements within a certain range with this XSLT:

    
      
      
      
    
      
          
              
           
      
    
      
        
          
        
      
    
      
        
          
            
          
        
      
    
    
    

    (Note, by the way, that because this is based on the identity transform, it works even if header isn't the top-level element.)

    You still need to count the data elements in the source XML, and run the transform repeatedly with the values of $startPosition and $endPosition that are appropriate for the situation.

提交回复
热议问题