How to read a .edmx file (which has multiple namespaces)

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im 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.
Ive 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 cant get to the <edmx:ConceptualModels> section.
I believe its all in how Ive defined my Namespaces using XmlNamespaceManager. I cant figure out how to define those so I can access the <edmx:ConceptualModels> section.
<pre class="prettyprint 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");
}
}
}
}
[/code]
<br/>
Thanks...
CT
<br/>

View the full article
 
Back
Top