I also tried to load the hbm into an XmlDocument and modify it but I keep on getting errors.
Code:
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("Model/Driver.hbm.xml");
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmldoc.NameTable);
nsMgr.AddNamespace("nh", "urn:nhibernate-mapping-2.2");
XmlNode node = xmldoc.SelectSingleNode("/nh:hibernate-mapping/nh:class/nh:dynamic-component",nsMgr);
XmlElement element = xmldoc.CreateElement("property");
//Create new attribute Name
XmlAttribute attrName = xmldoc.CreateAttribute("name");
attrName.Value = "NewField";
//Create new attribute Type
XmlAttribute attrType = xmldoc.CreateAttribute("type");
attrType.Value = "string";
//Add the attributes to the property node
element.Attributes.Append(attrName);
element.Attributes.Append(attrType);
//Append the propperty node
node.AppendChild(element);
Configuration.AddDocument(XmlDoc)
I see that an attribute xmlns="" is added to the "property" and I assume that is the problem, but I don't know how I can remove this.
I get the following error:
Quote:
NHibernate.MappingException: (XmlDocument)(10,8): XML validation error: The element 'dynamic-component' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property'. List of possible elements expected: 'property, many-to-one, one-to-one, component, dynamic-component, any, map, set, list, bag, array, primitive-array' in namespace 'urn:nhibernate-mapping-2.2'.
Any suggestions?