tags:

views:

39

answers:

1

I am trying to dynamically create a XML for a webservice but when I test the service I get the following error

XML Parsing Error: no element found Location: http://stuiis.cms.gre.ac.uk/dd615/aspweb/WatCoursework/Service.asmx/getMusicdetailsSql Line Number 1, Column 39: --------------------------------------^

// Make a new XML document in memory.
        XmlDocument doc = new XmlDocument();

        // Fill this document with a root element
        // named <Inventory>.
        XmlElement musicInformation = doc.CreateElement("musicInformation");

        using (SqlDataReader oDr = myCommand.ExecuteReader())
        {
            while (oDr.Read())
            {
                // Now, make a sub element named <Car> with
                // an ID attribute.
                XmlElement musicdetails = doc.CreateElement("musicdetails");
                musicdetails.SetAttribute("m_id", oDr["m_id"].ToString());

                // Build the data within the <Car> element.
                XmlElement p_id = doc.CreateElement("p_id");
                p_id.InnerText = oDr["p_id"].ToString();

                XmlElement artistname = doc.CreateElement("artistname");
                artistname.InnerText = oDr["artistname"].ToString();

                XmlElement recordname = doc.CreateElement("recordname");
                recordname.InnerText = oDr["recordname"].ToString();

                XmlElement recordtype = doc.CreateElement("recordtype");
                recordtype.InnerText = oDr["recordtype"].ToString();

                XmlElement format = doc.CreateElement("format");
                format.InnerText = oDr["format"].ToString();

                XmlElement price = doc.CreateElement("price");
                price.InnerText = oDr["price"].ToString();


                musicdetails.AppendChild(p_id);
                musicdetails.AppendChild(artistname);
                musicdetails.AppendChild(recordname);
                musicdetails.AppendChild(recordtype);
                musicdetails.AppendChild(format);
                musicdetails.AppendChild(price);

                musicInformation.AppendChild(musicdetails);
            }
            return doc;
        }
+2  A: 

I think you forgot to add the musicInformation to the document:

        }
        doc.AppendChild(musicInformation);
        return doc;
    }
Dean Harding