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 8608417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:36:20+00:00 2026-06-12T03:36:20+00:00

string parseData= <TEST xmlns:dt=\urn:schemas-microsoft-com:datatypes\><A dt:dt=\string\>10</A><B dt:dt=\string\>20</B></TEST>; DataSet ds = new DataSet(Whatev); TextReader txtReader =

  • 0
           string parseData= "<TEST xmlns:dt=\"urn:schemas-microsoft-com:datatypes\"><A dt:dt=\"string\">10</A><B dt:dt=\"string\">20</B></TEST>";

            DataSet ds = new DataSet("Whatev");

            TextReader txtReader = new StringReader(parseData);
            XmlReader reader = new XmlTextReader(txtReader);
            ds.ReadXml(reader);
            DataTable ad = new DataTable("newT");
            ad.ReadXml(reader);

For this I am getting empty table in ad, and three tables in ds.
What I am expecting is,
one table with two columns A and B, and one row with values 10 and 20.

What am I doing wrong?

  • 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-06-12T03:36:21+00:00Added an answer on June 12, 2026 at 3:36 am

    You’re simply not using it correctly. There’s a number of problems:

    1. You are reading from the same stream twice. In the first pass, the stream pointer is at the end of the stream. You attempt to read from it again when it’s already at the end so nothing else is read. Either read into your data set or into your data table, not both. Or, at least seek back to the beginning of the stream if you really want to.

    2. Your XML is not in the correct format. It has to be in the format:

      <SomeRoot>
          <TableName>
              <ColumnName>ColumnValue</ColumnName>
          </TableName>
          <TableName>
              <ColumnName>AnotherColumnValue</ColumnName>
          </TableName>
      </SomeRoot>
      

      You won’t be able to use that method with any arbitrary XML.

    3. Your tables do not have a schema set. You need to either read in a schema or set it up beforehand.

      var table = new DataTable("TEST");
      table.Columns.Add("A", typeof(string));
      table.Columns.Add("B", typeof(string));
      table.ReadXml(xmlReader);
      

    Try this instead:

    var xmlStr = @"<Root>
        <TEST>
            <A>10</A>
            <B>20</B>
        </TEST>
    </Root>";
    var table = new DataTable("TEST");
    table.Columns.Add("A", typeof(string));
    table.Columns.Add("B", typeof(string));
    table.ReadXml(new StringReader(xmlStr));
    

    If you decide to parse that XML yourself, LINQ can help you out here.

    public static DataTable AsDataTable(XElement root, string tableName, IDictionary<string, Type> typeMapping)
    {
        var table = new DataTable(tableName);
    
        // set up the schema based on the first row
        XNamespace dt = "urn:schemas-microsoft-com:datatypes";
        var columns =
           (from e in root.Element(tableName).Elements()
            let typeName = (string)e.Element(dt + "dt")
            let type = typeMapping.ContainsKey(typeName ?? "") ? typeMapping[typeName] : typeof(string)
            select new DataColumn(e.Name.LocalName, type)).ToArray();
        table.Columns.AddRange(columns);
    
        // add the rows
        foreach (var rowElement in root.Elements(tableName))
        {
            var row = table.NewRow();
            foreach (var column in columns)
            {
                var colElement = rowElement.Element(column.ColumnName);
                if (colElement != null)
                    row[column.ColumnName] = Convert.ChangeType((string)colElement, column.DataType);
            }
            table.Rows.Add(row);
        }
        return table;
    }
    

    Then to use it:

    var xmlStr = @"<Root>
        <TEST xmlns:dt=""urn:schemas-microsoft-com:datatypes"">
            <A dt:dt=""string"">10</A>
            <B dt:dt=""string"">20</B>
        </TEST>
    </Root>";
    var root = XElement.Parse(xmlStr);
    var mapping = new Dictionary<string, Type>
    {
        { "string", typeof(string) },
    };
    var table = AsDataTable(root, "TEST", mapping);
    

    There probably is a better way to get the associated .NET type for a datatype but I don’t know how to do that at the moment, I’ll update if I find that out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//string NSString *haystack = @.test {test:test} .test2{dasf:asdF}; //pattern NSString *needle = @[^{}]*{[^{}]*}; What I
I want to parse data-action in the string below. I've managed to get the
string a = sea; string b = SEA if (a == b)... How could
String baseString=POST&; String subBaseString = oauth_consumer_key=+oauth_consumer_key+&oauth_nonce=+nonce+&oauth_signature_method=+oauth_signature_method; subBaseString += &oauth_timestamp=+ oauth_timestamp+&oauth_token=+oauth_token+&oauth_version=1.0; baseString += URLEncoder.encode(baseRequest, UTF-8);
string in question: '{images:{0:<div style=\\background:red;width:250px;height:250px;display:block;position:absolute;\\></div>}}' I've tried various combinations of single and double quotes.
string name = bob; object obj = name; obj = joe; Console.WriteLine(name); I'm a
String str = abcde123_92qwq_1a_02x_1e; I want to replace the first string part between the
string abc = 07:00 - 19:00 x = int.Parse(only first two characters) // should
string one = find; combobox1.text = one; I want to use one i.e string
i want to use string streams in memory instead of a file stream to

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.