Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am trying to read in some XML from my database. I am running in to a bit of a problem. When I try use XDocument.Parse(xml) it is reading it all as one element. NextNode and PreviousNode are both null. Below is the XML I receive from the database:
XML
<extradata><client><weburl>http://wwww.mywebaddress.com</weburl><subscriptions><usermanagement allowed="true" /><formdesign allowed="true" /><formview allowed="true" /></subscriptions><mobileconfig><gps allowed="false" /><photoattach allowed="true" /><barcode allowed="false" /><verification allowed="false" /></mobileconfig><pcrouterconfig><printondemand allowed="true" /><integration allowed="false" /><printany allowed="false" /></pcrouterconfig></client></extradata>


The error I get when I do get an error is that there is no root node? Any help would be great.
Posted
Comments
Herman<T>.Instance 9-Mar-12 11:06am    
please show code that gets the data from db

Here is the sample XML parser method as:

C#
void ParseURL(string strUrl)
{
    try
    {
        XmlTextReader reader = new XmlTextReader(strUrl);
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
            case XmlNodeType.Element:
                Hashtable attributes = new Hashtable();
                string strURI= reader.NamespaceURI;
                string strName= reader.Name;
                if (reader.HasAttributes)
                {
                    for (int i = 0; i < reader.AttributeCount; i++)
                    {
                        reader.MoveToAttribute(i);
                        attributes.Add(reader.Name,reader.Value);
                    }
                }
                StartElement(strURI,strName,strName,attributes);
            break;
             //
             //you can handle other cases here
             //
 
             //case XmlNodeType.EndElement:
             // Todo
             //case XmlNodeType.Text:
             // Todo
            default:
            break;
        }
    }
    catch (XmlException e)
    {
        Console.WriteLine("error occured: " + e.Message);
    }
}
 
Share this answer
 
use this sample code:


C#
using System.Xml;
using System.Data.SqlClient;
class Example
{
static void Main()
{
SqlConnection c=new SqlConnection();
c.ConnectionString="*******************************";
c.Open();
SqlDataAdapter adptr=new SqlDataAdapter("Select * from your_table_name",c);
DataSet ds=new DataSet();
adptr.Fill(ds,"your_table_name");
ds.WriteXml("C:\\your_table_name.xml",XmlWriteMode.DiffGram);
c.Close();
}
}


i hope this code will surely help you....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900