Search code examples
c#.netxmlsubsonic

How to extract attribute from a XML field with Subsonic?


I have a SQL query like this :

SELECT      
     myXmlField.value('(./row/@myAttribute)[1]', 'nVarchar(max)') as myAttribute
FROM myTABLE
   Where myID = 640

The SQL query works fine, but now, how can I extract the attribute from the XML field that I have in MS SQL Server, with Subsonic?

I am using Visual Studio 2005, .net 2.0, C#, and SubSonic 2.1.

Thanks a lot.


Solution

  • Well... I solved it loading the value of the XML field, subsonic returns it as a string, in a XmlDocument object.

    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    doc.LoadXml(MyTable.myXmlField); //MyTable entitie created by subsonic.
    doc.SelectSingleNode("./row/@myAttribute").Value //Here I get the attribute from the XML field.
    

    Any other way to do it?