Why use an empty element in XML?

前端 未结 3 2325
[愿得一人]
[愿得一人] 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:07

    From my experience, Ive come across many of these formats when using APIs. Sometimes, the API creator has variables that are empty, thus resulting in these empty XML tags. For example, let's say you are creating a website that gathers hotel availability for different hotels. Company A ( some hotel company ) provides you with access to their API. You send a request and they provide you with the following:

    
      2008-01-10
      TRUE
    
    

    But Sometimes you may get:

    
      2008-01-10
      FALSE
    
    

    Or sometimes you may get:

    
      2008-01-10
      
    
    

    As a developer, you have to create code that is ready for any type of response since we dont know exactly how the data is sent back from the API creators, which is why this is mentioned in tutorials. Hope this helps.

提交回复
热议问题