2

my xml is like below

<Expression>
    <Field>X</Field>
    <Formula>a+b</Formula>          
</Expression>
<Expression>
    <Field>Y</Field>
    <Formula>a-b</Formula>          
</Expression>
<Expression>
    <Field>Z</Field>
    <Formula>a*b</Formula>          
</Expression>

my c# page

DataSet ds = new DataSet();           
ds.ReadXml(@"C:\\Test.xml");
GridView1.DataSource = ds;
GridView1.DataMember = ds.Tables[0].ToString();
GridView1.DataBind();

it keeps showing me error:

There are multiple root elements. Line 6, position 4.

1
  • Add a general root out of the expression elements Commented Dec 30, 2013 at 12:02

1 Answer 1

3

Xml file must have single root element, which have other elements as children. Currently you have several Expression elements on root level. Wrap them into some Expressions element to make your xml file valid:

<Expressions>
  <Expression>
    <Field>X</Field>
    <Formula>a+b</Formula>
  </Expression>
  <Expression>
    <Field>Y</Field>
    <Formula>a-b</Formula>
  </Expression>
  <Expression>
    <Field>Z</Field>
    <Formula>a*b</Formula>
  </Expression>
</Expressions>

Your xml loading code is valid. It creates DataSet with single DataTable named Expression. That table has two columns (Field and Formula) and three rows with data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.