dimanche 4 octobre 2015

Read xml data with namespaces from SQLite database in C#

I'm confronted with a XML structure from a SQLite database with two namespaces. How can I reference to 'floatnumber' (behind second ns) when no attribute name is present?

<?xml version="1.0" encoding="utf-8"?>
<anyType xmlns:q1="http://ift.tt/tphNwY"
         d1p1:type="q1:string" 
         xmlns:d1p1="http://ift.tt/ra1lAU">
   floatnumber
 </anyType>

Connecting with package v1.0.98.0 from http://ift.tt/1pLXZDc to SQLite database was straight forward. I was playin around with XmlReader and XDocument (LINQ-to-XML) but no success.

What is the best way to read 'floatnumber' (database column 'Value') from xml in C# ?

using (SQLiteCommand sqlcmd = new SQLiteCommand())
{
    sqlcmd.Connection = connect;
    sqlcmd.CommandText = sqlquery;
    SQLiteDataReader rdr = null;
    try
    {
        rdr = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);
        while (rdr.Read())
        {
            string xmlstr = rdr["Value"].ToString();
            Console.WriteLine(xmlstr);                  // gives whole xml structure

            /* code to get floatnumber from xml */
        }
    }
    catch ()
    {}
}

My first post here. Tom

Aucun commentaire:

Enregistrer un commentaire