Converting DataSet into XML with nested elements

后端 未结 3 1211
悲&欢浪女
悲&欢浪女 2021-01-27 03:03

I am writing a WebService that is supposed to convert DataSet into XML. My DataSet is actually list of hotels with categories. Each hotel can belong to one or more categories. I

3条回答
  •  走了就别回头了
    2021-01-27 03:43

    You could write an sql that would produce the desired model, in xml format directly from the database, like...

    SELECT HotelName,
           (select CategoryName from HotelCategories 
           where CategoryHotelName=HotelName
           for xml path('Category')) as Categories 
    FROM Hotels 
    for xml path('Hotels')
    

    Ofcourse depending on your DB layout...

提交回复
热议问题