remove root node xml - vb.net

hi i'm doing some work in vb.net and want to remove the root node in an XML file making the next node the root,

I know i could use text reader and remove the first and last lines but if possible i would like to do this without using a text reader.

if you see the xml example below i wish to remove the <import> node i've been trying various things but can only remove child nodes.
<import>
  <cXML xml:lang="en" ID="1234" timestamp="2010-04-03T16:11:04">
    <Header>
      <From>
        <Credential domain="MyOrganisation">
          <Identity>123456</Identity>
        </Credential>
      </From>
    </Header>
  </cXML>
</import>

Open in new window

IanPaskinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
Easiest way:
Regex.Replace(xmlText, "</?import>", String.Empty)

I hope you know how to read xml from file to string xmlText?
0
Hawkvalley1Commented:
   'make initial file
    Dim str As String = "<import>"
    str = String.Concat(str, Environment.NewLine, "<cXML xml:lang=""en"" ID=""1234"" timestamp=""2010-04-03T16:11:04"" >")
    str = String.Concat(str, Environment.NewLine, "     ", "<Header>")
    str = String.Concat(str, Environment.NewLine, "     ", "<From>")
    str = String.Concat(str, Environment.NewLine, "     ", "     ", "<Credential domain=""MyOrganisation"" >")
    str = String.Concat(str, Environment.NewLine, "     ", "     ", "     ", "<Identity>123456</Identity>")
    str = String.Concat(str, Environment.NewLine, "     ", "     ", "</Credential>")
    str = String.Concat(str, Environment.NewLine, "     ", "</From>")
    str = String.Concat(str, Environment.NewLine, "     ", "</Header>")
    str = String.Concat(str, Environment.NewLine, "     ", "</cXML>")
    str = String.Concat(str, "</import>")
    Dim xl As New XmlDocument
    xl.LoadXml(str)
    xl.Save("C:\Test\EExml.xml")

    Dim xmls As New XmlDocument
    'copy only the inner part
    xmls.LoadXml(xl.DocumentElement.InnerXml)
    'save to the same file all done =)
    xmls.Save("C:\Test\EExml.xml")
0
Hawkvalley1Commented:
Since your file probably already exists:

   Dim xl As New XmlDocument
    xl.Load(C:\yourfile.xml")
     
    Dim xmls As New  XmlDocument
    'copy only the inner part
     xmls.LoadXml(xl.DocumentElement.InnerXml)

    'save to the  same file all done =)
    xmls.Save("C:\youfile.xml")

   'dispose of cached memory
   xl = Nothing
   xmls = Nothing
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IanPaskinAuthor Commented:
perect thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.