XML attribute vs XML element

前端 未结 20 2247
暖寄归人
暖寄归人 2020-11-22 01:34

At work we are being asked to create XML files to pass data to another offline application that will then create a second XML file to pass back in order to update some of ou

20条回答
  •  囚心锁ツ
    2020-11-22 01:58

    It's largely a matter of preference. I use Elements for grouping and attributes for data where possible as I see this as more compact than the alternative.

    For example I prefer.....

    
    
        
             
            
            
        
    
    

    ...Instead of....

    
    
        
            
                Rory
                Becker
                30
            
            
                Travis
                Illig
                32
            
            
                Scott
                Hanselman
                34
            
        
    
    

    However if I have data which does not represent easily inside of say 20-30 characters or contains many quotes or other characters that need escaping then I'd say it's time to break out the elements... possibly with CData blocks.

    
    
        
            
                A programmer whose interested in all sorts of misc stuff. His Blog can be found at http://rorybecker.blogspot.com and he's on twitter as @RoryBecker
            
            
                A cool guy for who has helped me out with all sorts of SVn information
            
            
                Scott works for MS and has a great podcast available at http://www.hanselminutes.com 
            
        
    
    

提交回复
热议问题