How to read a .edmx file (which has multiple namespaces)
-
Monday, December 10, 2012 6:30 PM
I'm trying to write a small utility app (C#) that traverses through a .edmx file (Entity Framework generated) looking for specific XML elements.
This is NOT for use during runtime. This is just a raw, XML file (.edmx) that needs manipulating.
I've successfully found the <edmx:StorageModels> section, but there is also the <edmx:ConceptualModels> section which has been a problem. Below is an example of what I have thus far. I just can't get to the <edmx:ConceptualModels> section.
I believe it's all in how I've defined my Namespaces using XmlNamespaceManager. I can't figure out how to define those so I can access the <edmx:ConceptualModels> section.
XmlDocument edmxFile = new XmlDocument(); edmxFile.Load(pathFile); XmlNamespaceManager nsMan = new XmlNamespaceManager(edmxFile.NameTable); nsMan.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2008/10/edmx"); nsMan.AddNamespace("s", "http://schemas.microsoft.com/ado/2009/02/edm/ssdl"); XmlNodeList entityTypes = edmxFile.DocumentElement.SelectNodes("//s:EntityType", nsMan); foreach (XmlNode xn in entityTypes) { if (xn.Attributes[0].Value == "TARGET_LON_LAT_NAV_V") { foreach (XmlElement xe in xn.ChildNodes) { if (xe.Name == "Property") { //xe.SetAttribute("Nullable", "false"); } } } }
Thanks...
CT
- Edited by CrazyTasty Monday, December 10, 2012 6:33 PM
All Replies
-
Monday, December 10, 2012 7:38 PM
Figured it out. By adding the following namespace (to the existing namespaces) and a separate xpath reference for the EntityTypes.
nsMan.AddNamespace("c", "http://schemas.microsoft.com/ado/2008/09/edm"); XmlNodeList entityTypes2 = edmxFile.DocumentElement.SelectNodes("//c:EntityType", nsMan);- Marked As Answer by CrazyTasty Monday, December 10, 2012 7:39 PM

