I have a generated xml (dbml) document that I have to add new elements to.. here's an amended snippet..
<?xml version="1.0" encoding="utf-8"?>
<Database Name="mydb" EntityNamespace="MyEntity" ContextNamespace="MyEntity" Class="MyClass" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
<Table Name="dbo.MYTABLE" Member="MYTABLE">
<Type Name="MYTABLE">
<Column Name="keycol" Member="keycol" Type="System.String" DbType="VarChar(10) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="fkcol" Member="fkcol" Type="System.String" DbType="VarChar(10) NOT NULL" CanBeNull="false" />
<Association Name="myfkid" Member="FKTBL" ThisKey="fkcol" OtherKey="fkcol" Type="FKTBL" IsForeignKey="true" DeleteOnNull="true" />
</Type>
</Table>
I can add a new element ok using the following VB code..
'xDoc is my loaded XMLDocument
xElement = xDOC.CreateElement("Association")
AddAttribute(xElement, "Name", FK.rolename)
'add all other attribs..
ParentNode.AppendChild(xElement)
Private Sub AddAttribute(ByRef xElement As XmlElement, ByVal Key As String, ByVal Value As String)
Dim NewAttr As XmlAttribute
NewAttr = xDOC.CreateAttribute(Key)
NewAttr.Value = Value
xElement.Attributes.Append(NewAttr)
End Sub
Now, this all works fine except that when I export the document, it adds an extra attribute to the added element of xmlns="" e.g.
<Association Name="mynewfkid" Member="mynewtbl" ThisKey="mykeycol" OtherKey="otherkeycol" Type="mynewtbl" DeleteRule="CASCADE" xmlns="" />
How do I add the element so that the serializer doesn't add the extra namespace attribute ?

Signature
Adrian
Martin Honnen - 13 Mar 2008 18:54 GMT
> I have a generated xml (dbml) document that I have to add new elements
> to.. here's an amended snippet..
[quoted text clipped - 19 lines]
>
> xElement = xDOC.CreateElement("Association")
You need to pass the namespace to the CreateElement method e.g.
Const dbml As String = _
"http://schemas.microsoft.com/linqtosql/dbml/2007"
xElement = xDoc.CreateElement("Association", dbml)
Do that for each element you want to create in that namespace.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Adrian - 13 Mar 2008 21:28 GMT
Thanks Martin, that did the trick.
| > I have a generated xml (dbml) document that I have to add new elements
| > to.. here's an amended snippet..
[quoted text clipped - 25 lines]
| xElement = xDoc.CreateElement("Association", dbml)
| Do that for each element you want to create in that namespace.