How can I create a schema from an example XML document in Perl?

前端 未结 1 1669
甜味超标
甜味超标 2021-01-05 11:30

I need to create a XSD schema based on a XML file. Are there any Perl modules which can do this?

1条回答
  •  耶瑟儿~
    2021-01-05 12:15

    You can create the XSD by a XSL transformation using any XSLT processor. See XML::XSLT

    An XSD file contains two element types: simple and complex. All leaf nodes have to be translated into simple type elements and the others have to be translated into complex types. Leaf nodes are nodes without any descendants. The corresponding XPath is //*[not(descendant::element())]. The following XSLT implements this approch:

    
    
      
      
        
          
            
              
                
              
              
                
              
            
          
          
            
              
                
              
              
                
                  
                    
                      
                        
                      
                    
                  
                
              
            
          
        
      
    
    

    The following example:

    
    
      Peter
      Pan
      
        1904
        12
        27
      
    
    

    Will produce the following schema:

    
    
      
        
          
        
      
      
        
          
        
      
      
        
          
        
      
      
        
          
        
      
      
        
          
        
      
      
        
          
            
            
            
          
        
      
      
        
          
            
            
            
          
        
      
    
    

    0 讨论(0)
提交回复
热议问题