Why use an empty element in XML?

前端 未结 3 2323
[愿得一人]
[愿得一人] 2021-02-20 15:36

Rank amateur here. I get the instructions on HOW to use an empty element in XML. But why would you? What would it be used for, other than (I guess) to add a blank record when th

3条回答
  •  既然无缘
    2021-02-20 16:00

    If a schema requires that a tag be present in a certain order, you may need to include that tag even if it has an empty value. For example, the following fragment from a schema indicates you need tag foo before tag bar:

    
      
        
          
          
        
      
    
    

    so the following fragment would be valid:

    
      
      asdf!
    
    

    But the following would not:

    
      asdf!
    
    

    Additionally, you can use an empty tag to represent an empty value (as opposed to a null value). However, if you're trying to represent a null value in XML, you should really use an xsi:nil attribute

提交回复
热议问题