Help with renaming and deleting tables in an xml file using VB.NET

Hi,

How do you rename a table and also delete a particular table? Foe example if I have

<Root>
 -<fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">
<IemA>
<IemB>
</fields>
-<fNSC>
<IemA>
</NSC>
</Root>

How do I obtain

<Root>
 -<fiels>
<IemA>
<IemB>
</fields>
</Root>
vcharlesAsked:
Who is Participating?
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.

Fernando SotoRetiredCommented:
Hi Victor;

The XML structure given under the title "How do I obtain" is invalid. For example <fiels> has no end tag and </fields> has no begin tag. Also <IemA> and <IemB> have no end tag or did you mean to have this <IemA /> and <IemB />. Also are all these nodes to have no data associated with them?

<Root>
  <fiels>
    <IemA>
    <IemB>
  </fields>
</Root>

Open in new window

0
vcharlesAuthor Commented:
Hi Fernando,

I will send you another example shortly
Yes, the data elements will contain data.
Thsnks
Victor
0
vcharlesAuthor Commented:
From:

<Root>
  -<fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">
 <IemA>xxxx</ItemA>
 <IemB>yyyy</ItemB>
 </fields>
 -<NSC>
 <IemA>ggggg</ItemA>
 </NSC>
 </Root>

 How do I obtain

<Root>
  <fields>
 <IemA>xxxx</ItemA>
 <IemB>yyyy</ItemB>
 </fields>
 </Root>

Thanks.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Fernando SotoRetiredCommented:
Hi Victor;

The following code snippet should do what you need.

'' Load XML document
Dim xdoc = XDocument.Load("From Path and XML File Name")

'' Find all nodes that do not have the tag name fields.
Dim results As List(Of XElement) = (From n In xdoc.Root.Elements() _       
                                    where Not (n.Name = "fields") _        
                                    Select n).ToList()        
             
'' Remove all the nodes in the list                                                                           
results.ForEach( Sub(n) n.Remove() )
'' Remove attribute from fields node                                       
xdoc.Root.Elements("fields").ToList().ForEach( Sub(a) a.RemoveAttributes())
'' Save the document
xdoc.Save("To Path and XML File Name")                                                

Open in new window

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
vcharlesAuthor Commented:
Thank you, I will try it later and get back to you.

Victor
0
vcharlesAuthor Commented:
Thank You.
0
Fernando SotoRetiredCommented:
Not a problem Victor, glad to help.
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.