Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4118754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:00:06+00:00 2026-05-20T23:00:06+00:00

I am writing a WebService that is supposed to convert DataSet into XML. My

  • 0

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 followed an example from HERE and it works well except I don’t get result that I would like.

This is what I get: (example 1)

<hotels>
    <hotel>
        <name>Hilton Resort</name>
        <category>
            <catname>Hotel</catname>
        </category>
        <category>
            <catname>Resort</catname>
        </category>
        <category>
            <catname>Golf & Spa</catname>
        </category>
    </hotel> 
    <hotel>
        <name>Hyatt</name>
        <category>
            <catname>Resort</catname>
        </category>
        <category>
            <catname>Golf & Spa</catname>
        </category>
    </hotel> 
</hotel>

but, I would like to get something like this: (example 2)

<hotels>
    <hotel>
        <name>Hilton Resort</name>
        <categories>  
            <catname>Hotel</catname>
            <catname>Resort</catname>
            <catname>Golf & Spa</catname>
        </categories>
    </hotel> 
    <hotel>
        <name>Hyatt</name>
        <categories>  
            <catname>Hotel</catname>
            <catname>Golf & Spa</catname>
        </categories>
    </hotel> 
</hotel>

Here is my current code that produces XML as in example 1:

        ...
        ...
        SqlDataAdapter hotelDA = new SqlDataAdapter(SQLHotels, SQLConn);
        SqlDataAdapter catDA = new SqlDataAdapter(SQLCats, SQLConn);

        DataSet ds = new DataSet("Hotels");

        hotelDA.Fill(ds, "Hotel");
        catDA.Fill(ds, "Category");

        DataRelation SleepRel = ds.Relations.Add("Hotel",
                 ds.Tables["Sleep"].Columns["Id"],
                 ds.Tables["Category"].Columns["AccID"]);
        SleepRel.Nested = true;
        SQLConn.Close();
        return ds;

SQLHotels – SQL SELECT statement that selects all hotels
SQLCats – SQL SELECT statement that selects all categories
Id – hotel ID
AccId – hotel ID in table Category (foreign key)

My questions:
1) Does it actually matter? Is one structure better then another one?
2) Is it possible to make relation between two tables in DataSet so I get output like it is in second (desired) XML example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:00:06+00:00Added an answer on May 20, 2026 at 11:00 pm

    Is one structure better than the other one?

    Better for what? The DataSet‘s format is very good if you want to be able to read the data back into a DataSet, so by that standard, at least, it’s superior to the one you’re proposing.

    Generally speaking, when you process an XML document, you will be searching it for the elements that you want to work with using XPath or Linq. Compare:

    var categories = hotelElement.SelectNodes("category");
    var categories = hotelXElement.Elements("category");
    

    with:

    var categories = hotelElement.SelectNodes("categories/category");
    var categories = hotelXElement.Elements("categories").Element("category");
    

    What does having intermediate categories elements get you? The XML looks a little bit nicer in an editor. That’s generally not a compelling advantage, especially if it makes the XML a little harder to process.

    Is it possible to make relation between two tables in DataSet so I get output like it is in second (desired) XML example.

    No. The serialization format of the DataSet is very rigidly defined. It supports a couple of options (nesting, including the schema, diffgrams), but the format doesn’t change (unless you’re saving as diffgrams, but if you do that, how the XML looks is very low on your list of needs).

    You can use XSLT to change the format pretty readily, though. Add this to the identity transform:

    <xsl:template match="hotel">
       <xsl:apply-templates select="*[name() != 'category']"/>
       <xsl:if test="category">
          <categories>
             <xsl:apply-templates select="category"/>
          </categories>
       </xsl:if>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small iOS app that queries a XML REST webservice. The
Writing a client application that sends images to a server via a webservice. As
I'm writing a Cocoa app in Objective C that's communicating with a webservice and
I'm writing a JAX-WS WebService but I am running into a little stumbling block
I'm writing a webservice that is to be consumed by a third party tool.
I am writing a webservice that allows users to post files and then retrieve
I am writing a basic app that interacts with a webservice I'm writing using
I am writing a WebService using Java. Now I have a @WebMethod that is
I'm writing a RESTful webservice that returns custom/existing HTTP headers on successful/unsuccessful operations. For
I'm writing an android app that will connect to a REST/JSON webservice. Users will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.