Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parsing XML
Message
 
 
À
19/12/2014 12:08:40
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 5.0
OS:
Windows Server 2008
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01612438
Message ID:
01612443
Vues:
41
>>I was thinking that we want to convert XML to datatable first, but perhaps LINQ to XML will work as well.
>
>What would convert the XML to a datatable ?

I found our implementation of parsing quazi XML string into a dictionary. May be it can help
/*========================================================================================
       *                Dictionary<String, String> from SQML
       *=======================================================================================*/
      /// <summary>
      /// Populates a <string, string> dictionary using a SQML string.    
      /// </summary>
      /// <param name="tDictionary"></param>
      /// <param name="tcSQML"></param>
      public static void PopulateFromSQML(this Dictionary<String, Object> tDictionary, String tcSQML)
      {
         tDictionary.Clear();

         String pattern = @"<(?<field>[^/>]+)>(?<data>.*)</\k<field>>";

         MatchCollection matches = Regex.Matches(tcSQML, pattern, RegexOptions.Singleline);
         foreach (Match m in matches)
         {
            if (!tDictionary.ContainsKey(m.Groups["field"].ToString()))
               tDictionary.Add(m.Groups["field"].ToString(), m.Groups["data"]);
         }
      }
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform