How can I auto-indent XML nodes with XML::LibXML?

前端 未结 2 602
北海茫月
北海茫月 2021-01-12 18:57

I\'m adding nodes to my XML document as part some in-house processing, but cannot get XML::LibXML to auto-indent the added nodes.

I get output like the following:

2条回答
  •  天命终不由人
    2021-01-12 19:19

    I played a bit with settings and this seems to work:

    use XML::LibXML;
    
    my $doc = XML::LibXML->load_xml(string => < 1 });
                                        
                                            
                                            A
                                            45
                                            
            
                D
                3
                3
            
        
    
                                        
    END_XML
    
    print $doc->toString(1);
    

    Result is this:

    
    
      
        A
        45
        
          
            D
            3
            3
          
        
      
    
    

提交回复
热议问题