XML editing output tns: in each element

RocketSauce used Ask the Experts™
Ok, I have asked a similar question in the SQL 2005 section.  This question is similar but it pertains to VB.net and not SQL 2005.

Ok I have an xml file I need to generat for a 3rd party.  I have an empty shell of an xml file.  All I want to do is add some nodes to one of the child nodes.  

I want the xml to look like this


Thats all I want.....Because that is what the 3rd party XML Documents look like.  They do have the xmlns stuff up in their root nodes

I have tried this below and it fails...but if this command worked it would do all I need

Dim title As XmlElement = doc.CreateElement("tns:TPO")

If all my elements could look like the above line of code that would be great...but it errors out.  If you remove the colon it works fine but then the document is missing the required colon.

There is some code I am omitting here but if you need it I will supply it.

Any Ideas?  I can't figure out a normal way to do this.  I can think of an abnormal way to do it....

Dim title As XmlElement = doc.CreateElement("tnsTPO")
Then do some code to open and search the xml document for the string "tnsTPO" and replace it with "tns:TPO"

Any ideas?  I don't want any new additional xmlns stuff in these xml elements....because the 3rd party spec only has it on the root node and all other nodes only contain the "tns:" part.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Dim title As XmlElement = doc.CreateElement("tns", "TPO","")
Most Valuable Expert 2012
Top Expert 2014


This code from the article linked is what allowed the rest of my code to work.

  Dim ns As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
        ns.AddNamespace("a", "tns")

It still leaves the xmlns stuff in the root element which I'll live with

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial