Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2008

Tip: Looking for answers? Try searching our database.

Adding element to xml with existing namespace ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Adrian - 13 Mar 2008 18:32 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.