The Xml:

Micfosoft(TM)'s modified Books.xml:

The price attribute of the last book item was modified by me, now it appears two times,
once as attribute of book and second time as a separate item inside the book item.

<?xml version='1.0'?>
   <!-- This file represents a fragment of a book store inventory database -->
     <book genre="autobiography">
       <title>The Autobiography of Benjamin Franklin</title>
     <book genre="novel">
       <title>The Confidence Man</title>
     <book genre="philosophy" price="best">
       <title>The Gorgias</title>

My code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Books.Properties;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml;
using System.Windows.Forms;
using System.Xml.Schema;
using System.IO;

namespace Books
    public partial class Books : Form
        XmlDataDocument myXmlDataDocument = new XmlDataDocument();
        public Books()

            DataSet ds = new DataSet("Books DataSet");

            ds.ReadXml(@"../../Books.xml", XmlReadMode.InferSchema);

            dataGridView.DataSource = ds;

            dataGridView.DataMember = "book";

The runtime error is of course:


Column name 'price' defined for different mapping types.

Please help me find out how to define/refer in the code to these prices,
to be possible to read the xml!
I've been searching thorough google, but the most people were able to come up is "Change the xml",
the problem is that the actual xml that I'm working with, has been written in the same unfortunate fashion,
and can not be changed.


6 Years
Discussion Span
Last Post by Edvin76

Read xml doc through XDocuemt (LINQ).

XDocument doc = XDocument.Load(file);
            string att = "";
            foreach (XElement ele in doc.Descendants("book"))
                if (ele.HasAttributes)
                    att = "";
                    foreach (var at in ele.Attributes() )
                        att = att +  at.Name + " : " + at.Value;
                MessageBox.Show(ele.Name + " " + ele.Value +     att );
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.