CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Jun 2010
    Posts
    1

    Please help with reading tricky xml

    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.

    Code:
    <?xml version='1.0'?>
       <!-- This file represents a fragment of a book store inventory database -->
       <bookstore>
         <book genre="autobiography">
           <title>The Autobiography of Benjamin Franklin</title>
           <author>
             <first-name>Benjamin</first-name>
             <last-name>Franklin</last-name>
           </author>
           <price>8.99</price>
         </book>
         <book genre="novel">
           <title>The Confidence Man</title>
           <author>
             <first-name>Herman</first-name>
             <last-name>Melville</last-name>
           </author>
           <price>11.99</price>
         </book>
         <book genre="philosophy" price="best">
           <title>The Gorgias</title>
           <author>
             <name>Plato</name>
           </author>
           <price>9.99</price>
         </book>
       </bookstore>
    My code:

    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()
            {
                InitializeComponent();
    
                DataSet ds = new DataSet("Books DataSet");
    
                ds.ReadXml(@"../../Books.xml", XmlReadMode.InferSchema);
    
                dataGridView.DataSource = ds;
    
                dataGridView.DataMember = "book";
            }
        }
    }
    The runtime error is of course:

    http://i50.tinypic.com/2hezh8w.png

    Column name 'price' defined for different mapping types.

    Please help me find out how to define/refer in the code to this 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.


    _
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured