MVC5 querying XML data and stil keeping the rest of the model intact



The Tabel has multiple columns, one of them is a reference column (datatype XML) (I import the data from a other DB). The XML in the DB looks something like this.



<TrainReference xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY">
<ModelId>12345</ModelId>
<ModelType>Fast Train</ModelType>
....
....
</TrainReference>


This is a part of the model I use.



public class Trains
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column("TrainGuid", TypeName = "uniqueidentifier")]
[Display(Name = "Train Guid")]
public Guid TrainGuid { get; set; }

[Column("TrainReference", TypeName = "xml")]
[Display(Name = "Train Reference")]
public string TrainReference { get; set; }

....
....
}


This all functions, I can get the data from the DB and I can Store the Data into the DB using this model.


But the index page (view) looks something like this



Train Guid | Train Reference
2134.... | <TrainReference xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY"><ModelId>12345</ModelId>
3145.... | <TrainReference xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY"><ModelId>12355</ModelId>


When using the index page (view), I would like to have only 1 or 2 element(s) from the XML, without the XML formatting showing in the page.


So the result would look something like this.



Train Guid | Train - ModelType
2134.... | Fast Train
3145.... | Super Fast Train


How do I query the XML in this setting?


No comments:

Post a Comment